Skip to content

Tests: Improve tests to not rely on a .seconds(...) #8770

@bkhouri

Description

@bkhouri
Contributor

The some tests have the following expectation, or equivalent:

try #require(sync.wait(timeout: .now() + .seconds(2)) == .success)

This test is prone to flaky behaviour as the 2-second "timer" may or may not be sufficient.

We should update these affected tests to have a more deterministic assertion that does not rely on "timing" or any other behaviour that may cause a flaky tests.

Some suggestions:

  • Perhaps Removing the timeout value all-together altogether and specifying a test-level timeout
  • Getting away from that synchronous .wait call, and instead using something asynchronous

At the time of writing, the tests were:

  • BasicsTests.ConcurrencyHelpersTest/threadSafeArrayStore()
  • BasicsTests.ConcurrencyHelpersTest/threadSafeBox()
  • BasicsTests.ConcurrencyHelpersTest/threadSafeKeyValueStore()
  • CommandsTests.RunCommandTests/swiftRunSIGINT(buildSystem:)

Activity

changed the title [-]Tests: Improve ConcurrencyHelpersTests tests to not rely on a `.seconds(...)`[/-] [+]Tests: Improve tests to not rely on a `.seconds(...)`[/+] on Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test suiteimprovements to SwiftPM test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @bkhouri

      Issue actions

        Tests: Improve tests to not rely on a `.seconds(...)` · Issue #8770 · swiftlang/swift-package-manager