Skip to content

E2E test: Server-initiated close handling#310

Closed
s2x wants to merge 2 commits intomainfrom
oda-151-e2e-test-server-initiated-close-handling
Closed

E2E test: Server-initiated close handling#310
s2x wants to merge 2 commits intomainfrom
oda-151-e2e-test-server-initiated-close-handling

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented Mar 30, 2026

Closes #151

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

@s2x s2x closed this Mar 30, 2026
@s2x s2x deleted the oda-151-e2e-test-server-initiated-close-handling branch March 30, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2E test: Server-initiated close handling

1 participant