Skip to content

Fix flaky testDynamicPendable#43

Open
gibachan wants to merge 1 commit into
Quick:mainfrom
gibachan:fix-test
Open

Fix flaky testDynamicPendable#43
gibachan wants to merge 1 commit into
Quick:mainfrom
gibachan:fix-test

Conversation

@gibachan

Copy link
Copy Markdown
Contributor

Problem

A unit test testDynamicPendable fails on Darwin CI (swiftpm_darwin, swiftpm_darwin_15) while Linux environments continue to pass.

Root Cause

#30 bumps Nimble to 14.0.0 which changed the pollBlock implementation at Quick/Nimble@5a0cc37 .
pollBlock now iterates a fixed number of times instead of checking wall-clock time.

The number of iterations is calculated at https://github.com/Quick/Nimble/blob/727f75d91a0f7501d08d938966d17e6728b76a2a/Sources/Nimble/Utils/PollAwait.swift#L196 which evaluates to 100 in this case.

On Darwin CI, each await managedTask.isFinished evaluation requires an actor hop which takes additional time (~10ms). This makes the total polling duration approach PendableDefaults.delay (2 seconds):
100 × 10ms (eval) + 99 × 10ms (sleep) ≈ 2s

As a result, the Pendable 's fallback resolves during the toNever window, making isFinished become true and failing the assertion. On Linux, actor hops are fast enough that the total duration stays well below 2 seconds.

Fix

Replace toNever with deterministic assertions that don't rely on timing. Once subject.calls has one entry, the task is definitively suspended waiting for the PendableisFinished must be false at that point.

// Before
await expect { await managedTask.isFinished }.toNever(beTrue())

// After
await expect { await managedTask.hasStarted }.toEventually(beTrue())
await expect { subject.calls }.toEventually(haveCount(1))
await expect { await managedTask.isFinished }.to(beFalse())

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?

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.

1 participant