Skip to content

E2E test: Server-initiated close handling #151

@s2x

Description

@s2x

Problem

StreamConnection::dispatchServerPush() handles server-initiated close (key 0x0016) by sending a CloseResponse and closing the connection. However, no E2E test verifies this behavior. This is a critical path — in production, the server may close connections due to policy violations, resource limits, or administrative actions.

How to trigger

Server-initiated close can be triggered by:

  1. Deleting a stream while a consumer is subscribed to it (may trigger MetadataUpdate + Close)
  2. Using the RabbitMQ management API to force-close a connection
  3. Server shutdown/restart

Expected test

public function testServerInitiatedCloseIsHandledGracefully(): void
{
    $connection = Connection::create(...);
    $streamName = 'test-server-close-' . uniqid();
    $connection->createStream($streamName);

    // Force close via management API
    // curl -X DELETE http://localhost:15672/api/connections/...

    // Next operation should detect the closed connection
    $this->expectException(\RuntimeException::class);
    $this->expectExceptionMessage('Connection closed');
    $connection->createStream('another-stream');
}

Why it matters

  • Critical production scenario — servers close connections regularly
  • The dispatchServerPush() Close handler sends a response and calls $this->close(), but this path is untested
  • Without this test, regressions in close handling could cause silent data loss

Acceptance criteria

  • Verify isConnected() returns false after server-initiated close
  • Verify subsequent operations throw meaningful exceptions
  • Verify the client sends a proper CloseResponse before disconnecting

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions