Skip to content

Add comprehensive edge case tests for transport lifecycle #299

Description

@groupsky

Priority: MEDIUM

Description

PR #292 adds basic test for stop() during initialization, but several critical edge cases remain untested. These edge cases were identified during code review and represent real race conditions that could occur in production.

Missing Test Scenarios

High Priority

  1. Multiple stop() calls during initialization - Verify idempotency
  2. stop() racing with timeout - Verify timeout is cleared
  3. stop() racing with error event - Verify no double-rejection
  4. Concurrent start() during stop() - Verify no server orphaning

Medium Priority

  1. 'initialized' event firing after stop() - Verify handler doesn't set started=true
  2. Error event firing after stop() clears listeners - Verify defensive handling
  3. Rapid start/stop/start cycles - Stress test for state consistency

Example Test Structure

describe('edge cases', () => {
  it('should handle multiple stop() calls during initialization', async () => {
    const startPromise = transport.start()
    await Promise.all([
      transport.stop(),
      transport.stop(),
      transport.stop()
    ])
    await expect(startPromise).rejects.toThrow()
  })

  it('should clear timeout when stop() interrupts initialization', async () => {
    jest.useFakeTimers()
    const startPromise = transport.start()
    await transport.stop()
    jest.advanceTimersByTime(11000)
    // Verify no additional cleanup or errors occurred
  })
})

Benefits

  • Catches regression bugs
  • Documents expected behavior in edge cases
  • Validates all code paths are reachable and correct
  • Improves confidence in concurrent operation safety

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions