diff --git a/Tests/OTCoreTests/Atomics/Atomics Tests.swift b/Tests/OTCoreTests/Atomics/Atomics Tests.swift index 5e2d371..9c30158 100644 --- a/Tests/OTCoreTests/Atomics/Atomics Tests.swift +++ b/Tests/OTCoreTests/Atomics/Atomics Tests.swift @@ -73,6 +73,8 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { func testAtomic_BruteForce_ConcurrentMutations() { + let completionTimeout = expectation(description: "Test Completion Timeout") + class Foo { @Atomic var dict: [String: Int] = [:] @Atomic var array: [String] = [] @@ -115,7 +117,12 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { } } - g.wait() + DispatchQueue.global().async { + g.wait() + completionTimeout.fulfill() + } + + wait(for: [completionTimeout], timeout: 10) XCTAssertEqual(foo.dict.count, 0) XCTAssertEqual(foo.array.count, 0) @@ -127,6 +134,8 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { @available(macOS 10.15, macCatalyst 13, iOS 13, tvOS 13.0, watchOS 6.0, *) func testAtomic_BruteForce_ConcurrentWriteRandomReads() { + let completionTimeout = expectation(description: "Test Completion Timeout") + class Foo { @Atomic var dict: [String: Int] = [:] @Atomic var array: [String] = [] @@ -171,7 +180,12 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { } } - g.wait() + DispatchQueue.global().async { + g.wait() + completionTimeout.fulfill() + } + + wait(for: [completionTimeout], timeout: 10) timer.cancel() @@ -181,6 +195,8 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { /// This test is more useful with Thread Sanitizer on. func testAtomic_BruteForce_ConcurrentWriteAndRead() { + let completionTimeout = expectation(description: "Test Completion Timeout") + class Foo { @Atomic var dict: [String: Int] = [:] @Atomic var array: [String] = [] @@ -195,28 +211,31 @@ class Extensions_Swift_Atomics_Tests: XCTestCase { let iterations = 100_000 - DispatchQueue.global().async { - for index in 0.. 0 { _ = foo.array[0] } - } + for _ in 0.. 0 { _ = foo.array[0] } + readGroup.leave() } } - writeGroup.wait() - readGroup.wait() + DispatchQueue.global().async { + writeGroup.wait() + readGroup.wait() + completionTimeout.fulfill() + } + + wait(for: [completionTimeout], timeout: 10) }