@@ -22,18 +22,19 @@ class AsyncSemaphoreTests: XCTestCase {
2222 withDelay delay: UInt64 = UInt64 ( 5E9 ) ,
2323 durationInSeconds seconds: Int = 0
2424 ) async throws {
25- try await checkExecInterval ( for: {
26- try await withThrowingTaskGroup ( of: Void . self) { group in
27- for _ in 0 ..< count {
28- group. addTask {
29- await semaphore. wait ( )
30- try await Task . sleep ( nanoseconds: delay)
31- await semaphore. signal ( )
25+ try await checkExecInterval (
26+ for: {
27+ try await withThrowingTaskGroup ( of: Void . self) { group in
28+ for _ in 0 ..< count {
29+ group. addTask {
30+ await semaphore. wait ( )
31+ try await Task . sleep ( nanoseconds: delay)
32+ await semaphore. signal ( )
33+ }
3234 }
35+ try await group. waitForAll ( )
3336 }
34- try await group. waitForAll ( )
35- }
36- } , durationInSeconds: seconds)
37+ } , durationInSeconds: seconds)
3738 }
3839
3940 func checkSemaphoreWaitWithTimeOut(
@@ -45,20 +46,26 @@ class AsyncSemaphoreTests: XCTestCase {
4546 ) async throws {
4647 let semaphore = AsyncSemaphore ( value: value)
4748 let store = TaskTimeoutStore ( )
48- try await checkExecInterval ( for: {
49- try await withThrowingTaskGroup ( of: Void . self) { group in
50- for _ in 0 ..< count {
51- group. addTask {
52- let result = await semaphore. wait ( forNanoseconds: timeout)
53- result == . success ? await store. addSuccess ( ) : await store. addFailure ( )
54- try await Task . sleep ( nanoseconds: delay)
55- await semaphore. signal ( )
49+ try await checkExecInterval (
50+ for: {
51+ try await withThrowingTaskGroup ( of: Void . self) { group in
52+ for _ in 0 ..< count {
53+ group. addTask {
54+ let result = await semaphore. wait (
55+ forNanoseconds: timeout)
56+ result == . success
57+ ? await store. addSuccess ( )
58+ : await store. addFailure ( )
59+ try await Task . sleep ( nanoseconds: delay)
60+ await semaphore. signal ( )
61+ }
5662 }
63+ try await group. waitForAll ( )
5764 }
58- try await group . waitForAll ( )
59- }
60- } , durationInSeconds : seconds )
61- let ( successes , failures ) = ( await store . successes , await store . failures )
65+ } , durationInSeconds : seconds )
66+ let ( successes , failures ) = (
67+ await store . successes , await store . failures
68+ )
6269 XCTAssertEqual ( successes, value)
6370 XCTAssertEqual ( failures, UInt ( count) - value)
6471 }
@@ -115,5 +122,4 @@ class AsyncSemaphoreTests: XCTestCase {
115122 durationInSeconds: 8
116123 )
117124 }
118-
119125}
0 commit comments