Skip to content

Commit 5ce6b1a

Browse files
authored
test: add async signal tests for events (#17)
* test: add async signal tests for events * wip: improve test cases
1 parent 3c3c61b commit 5ce6b1a

15 files changed

+33
-45
lines changed

Sources/AsyncObjects/AsyncCountdownEvent.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
import OrderedCollections
84

Sources/AsyncObjects/AsyncEvent.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
/// An object that controls execution of tasks depending on the signal state.
84
///

Sources/AsyncObjects/AsyncSemaphore.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
import OrderedCollections
84

Sources/AsyncObjects/Continuation/ContinuableCollection.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
/// A type that manages a collection of continuations with an associated key.
84
///

Sources/AsyncObjects/Continuation/ContinuableCollectionActor.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
#if swift(>=5.7)
21
import Foundation
32

3+
#if swift(>=5.7)
44
/// An actor type that manages a collection of continuations with an associated key.
55
///
66
/// On `Swift 5.7` and above [actor isolation bug with protocol conformance](https://forums.swift.org/t/actor-isolation-is-broken-by-protocol-conformance/57040)
77
/// is fixed, and hence original protocol can be used without any issue.
88
typealias ContinuableCollectionActor = ContinuableCollection
99
#else
10-
@preconcurrency import Foundation
11-
1210
/// An actor type that manages a collection of continuations with an associated key.
1311
///
1412
/// This is to avoid [actor isolation bug with protocol conformance on older `Swift` versions](https://forums.swift.org/t/actor-isolation-is-broken-by-protocol-conformance/57040).

Sources/AsyncObjects/Continuation/TrackedContinuation.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
/// A mechanism to interface between synchronous and asynchronous code,
84
/// with tracking state data.

Sources/AsyncObjects/Future.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
/// An object that eventually produces a single value and then finishes or fails.
84
///

Sources/AsyncObjects/TaskQueue.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#if swift(>=5.7)
21
import Foundation
3-
#else
4-
@preconcurrency import Foundation
5-
#endif
62

73
import OrderedCollections
84

Tests/AsyncObjectsTests/AsyncCountdownEventTests.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ class AsyncCountdownEventTests: XCTestCase {
1717
try await event.wait(forSeconds: 5)
1818
}
1919

20+
func testWithIncrementSignalAfterSomeWait() async throws {
21+
let event = AsyncCountdownEvent()
22+
event.increment(by: 10)
23+
try await waitUntil(event, timeout: 5) { $0.currentCount == 10 }
24+
Task {
25+
try await Task.sleep(seconds: 1)
26+
await event.signal(concurrent: 10)
27+
}
28+
try await event.wait(forSeconds: 10)
29+
}
30+
2031
func testWithOverIncrement() async throws {
2132
let event = AsyncCountdownEvent()
2233
event.increment(by: 10)
@@ -78,7 +89,7 @@ class AsyncCountdownEventTests: XCTestCase {
7889
event.signal()
7990
try await event.wait(forSeconds: 5)
8091
self.addTeardownBlock { [weak event] in
81-
try await waitUntil(event, timeout: 5) { $0.assertReleased() }
92+
try await waitUntil(event, timeout: 10) { $0.assertReleased() }
8293
}
8394
}
8495

Tests/AsyncObjectsTests/AsyncEventTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ class AsyncEventTests: XCTestCase {
1010
try await event.wait(forSeconds: 3)
1111
}
1212

13+
func testSignalAfterSomeWait() async throws {
14+
let event = AsyncEvent(signaledInitially: false)
15+
Task {
16+
try await Task.sleep(seconds: 1)
17+
event.signal()
18+
}
19+
try await event.wait(forSeconds: 10)
20+
}
21+
1322
func testResetSignal() async throws {
1423
let event = AsyncEvent()
1524
event.reset()
@@ -29,7 +38,7 @@ class AsyncEventTests: XCTestCase {
2938
try await event.wait(forSeconds: 3)
3039
await task.value
3140
self.addTeardownBlock { [weak event] in
32-
try await waitUntil(event, timeout: 5) { $0.assertReleased() }
41+
try await waitUntil(event, timeout: 10) { $0.assertReleased() }
3342
}
3443
}
3544

0 commit comments

Comments
 (0)