Skip to content

E2E test: Connection resilience — operations after socket error#307

Merged
s2x merged 3 commits intomainfrom
oda-170-e2e-test-connection-resilience-operation
Mar 30, 2026
Merged

E2E test: Connection resilience — operations after socket error#307
s2x merged 3 commits intomainfrom
oda-170-e2e-test-connection-resilience-operation

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented Mar 30, 2026

Closes #170

Problem

No E2E test verifies client behavior when the underlying TCP socket encounters an error mid-session. In production, network partitions, server restarts, and load balancer timeouts cause socket errors.

Expected tests

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

    // Simulate socket error by stopping Docker container
    // or closing the socket via reflection

    $this->expectException(\RuntimeException::class);
    $connection->createStream('another-stream');
}

public function testIsConnectedReturnsFalseAfterSocketError(): void
{
    // After socket error, isConnected() should return false
}

Why it matters

  • Network failures are inevitable in production
  • The client must fail fast with clear errors, not hang or corrupt state
  • readBytes() returns null on SOCKET_ETIMEDOUT but throws on other errors — both paths need testing

Notes

  • This test may require Docker manipulation (stop/start container)
  • Alternative: use reflection to close the socket directly
  • Consider marking as @group slow or @group destructive

Acceptance criteria

  • Socket error → clear RuntimeException on next operation
  • isConnected() returns false after socket error
  • No resource leaks after socket error

Piotr Hałas added 3 commits March 30, 2026 14:37
- Remove unused $e variable in catch block (Rector)
- Add previous exception to ConnectionException (Rector)
- Fix socket type check in ConnectionResilienceTest (PHPStan)
@s2x s2x merged commit 32bbfb3 into main Mar 30, 2026
7 checks passed
@s2x s2x deleted the oda-170-e2e-test-connection-resilience-operation branch March 30, 2026 12:44
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: Connection resilience — operations after socket error

1 participant