[ECO-5397] Fix hanging typing tests#451
Conversation
WalkthroughRefactors sleep mechanism from duration-based to deadline-based across ClockProtocol, SystemClock, and TimerManager to improve test determinism. Updates test infrastructure with AsyncSemaphore synchronization and re-enables Swift tests in CI workflow. Changes
Sequence DiagramsequenceDiagram
participant Test
participant TimerManager
participant Clock
participant Handler
rect rgb(200, 240, 220)
Note over Test,Handler: New: Deadline-Based Approach
Test->>TimerManager: scheduleHandler(afterInterval)
TimerManager->>TimerManager: deadline = now + interval
TimerManager->>Clock: sleep(until: deadline)
alt deadline already passed
Clock->>Handler: invoke immediately
else deadline in future
Clock->>Clock: sleep(deadline - now)
Clock->>Handler: invoke after sleep completes
end
Handler->>Test: signals AsyncSemaphore
Test->>Test: waits for semaphore before asserting
end
rect rgb(220, 230, 240)
Note over Test,Handler: Previous: Duration-Based Approach (replaced)
Note over Test,Handler: ⚠️ No early-exit for past deadlines
Note over Test,Handler: ⚠️ Race conditions in tests without sync
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes The refactoring follows a consistent pattern across multiple files (duration → deadline), but the changes affect critical timing semantics requiring careful verification. Logic density is moderate with precomputation and early-exit optimization in TimerManager, and test synchronization patterns require validation for correctness and completeness. Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (4)**/*.swift📄 CodeRabbit inference engine (CLAUDE.md)
Files:
Tests/AblyChatTests/**/*.swift📄 CodeRabbit inference engine (CLAUDE.md)
Files:
Tests/AblyChatTests/**📄 CodeRabbit inference engine (CLAUDE.md)
Files:
Tests/AblyChatTests/Mocks/**/*.swift📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (4)Sources/AblyChat/TimerManager.swift (2)
Sources/AblyChat/ClockProtocol.swift (1)
Tests/AblyChatTests/Mocks/MockTestClock.swift (1)
Tests/AblyChatTests/TypingTimerManagerTests.swift (2)
🔇 Additional comments (12)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There's no guarantee that the clock.sleep call will have returned by the time that the clock.advance call returns.
beecf52 to
99d93db
Compare
99d93db to
8762623
Compare
8762623 to
497c27e
Compare
I'm still noticing an occasional hang in the integration tests, but I think that the majority of our test hangs were coming from the typing tests, so I'm re-enabling the SPM test CI step in order to be sure that these typing tests (which caused that CI step to hang) are fixed. Let's keep an eye on the integration tests. (It's good to have resolved most of the `swift test` hangs, because they were also limiting the utility of Claude Code, which kept hanging when trying to run the tests to verify its changes!) I'm also still observing the iOS unit tests taking substantially _longer_ to execute in CI than for other platforms. For example, the result of one test run (with the integration tests disabled): > ✔ Test run with 206 tests in 28 suites passed after 107.794 seconds. where for other platforms the unit test execution time is below 1 second. It looks like this is already covered by open issue #143, though.
497c27e to
de65183
Compare
|
I feel like each test should have begin/end timestamp. If this will not make it obvious what test(s) exactly causes hang, then we can try other things, wdyt? |
Could be interesting — could you have a think about how we'd achieve that? I'd suggest looking into Swift Testing's test hooks functionality (they don't call it that, forgot the term they use). But I don't think it should stop us from merging this? |
I'm still noticing an occasional hang in the integration tests, but I think that the majority of our test hangs were coming from the typing tests, so I'm re-enabling the SPM test CI step in order to be sure that these typing tests (which caused that CI step to hang) are fixed. Let's keep an eye on the integration tests.
(It's good to have resolved most of the
swift testhangs, because they were also limiting the utility of Claude Code, which kept hanging when trying to run the tests to verify its changes!)I'm also still observing the iOS unit tests taking substantially longer to execute in CI than for other platforms. For example, the result of one test run (with the integration tests disabled):
where for other platforms the unit test execution time is below 1 second.
It looks like this is already covered by open issue #143, though.
Relates to #295.
Summary by CodeRabbit
Tests
Refactor