@@ -28,15 +28,15 @@ struct TimerUtilsTests {
28
28
var callbackExecuted = false
29
29
30
30
let startTime = Date ( )
31
- let delayInterval : TimeInterval = 0. 2
31
+ let delayInterval : TimeInterval = 2
32
32
33
33
let timer = withDelay ( delayInterval) {
34
34
callbackExecuted = true
35
35
confirmation ( )
36
36
}
37
37
#expect( timer. isValid == true )
38
38
#expect( callbackExecuted == false )
39
- try await Task . sleep ( nanoseconds : 300_000_000 )
39
+ try await Task . sleep ( for : . seconds ( 5 ) )
40
40
41
41
#expect( callbackExecuted == true )
42
42
let elapsedTime = Date ( ) . timeIntervalSince ( startTime)
@@ -47,13 +47,13 @@ struct TimerUtilsTests {
47
47
@Test
48
48
func withDelayCanBeCancelled( ) async throws {
49
49
var callbackExecuted = false
50
- let timer = withDelay ( 0. 2) {
50
+ let timer = withDelay ( 2 ) {
51
51
callbackExecuted = true
52
52
}
53
53
#expect( timer. isValid == true )
54
54
55
55
timer. invalidate ( )
56
- try await Task . sleep ( nanoseconds : 300_000_000 )
56
+ try await Task . sleep ( for : . seconds ( 5 ) )
57
57
58
58
#expect( timer. isValid == false )
59
59
#expect( callbackExecuted == false )
@@ -62,11 +62,11 @@ struct TimerUtilsTests {
62
62
@Test
63
63
func withDelayRunsOnMainRunLoop( ) async throws {
64
64
try await confirmation { confirmation in
65
- let _ = withDelay ( 0. 2) {
65
+ let _ = withDelay ( 2 ) {
66
66
#expect( Thread . isMainThread)
67
67
confirmation ( )
68
68
}
69
- try await Task . sleep ( nanoseconds : 300_000_000 )
69
+ try await Task . sleep ( for : . seconds ( 5 ) )
70
70
}
71
71
}
72
72
}
@@ -78,20 +78,18 @@ final class TimerUtilsXCTests: XCTestCase {
78
78
var callbackExecuted = false
79
79
80
80
let startTime = Date ( )
81
- let delayInterval : TimeInterval = 0. 2
81
+ let delayInterval : TimeInterval = 2
82
82
83
83
let timer = withDelay ( delayInterval) {
84
84
callbackExecuted = true
85
85
expectation. fulfill ( )
86
86
}
87
87
XCTAssertTrue ( timer. isValid)
88
88
XCTAssertFalse ( callbackExecuted)
89
- // 0.3s will sometimes fail for macOS + 2021 platform
90
- await fulfillment ( of: [ expectation] , timeout: 1 )
89
+ await fulfillment ( of: [ expectation] , timeout: 5 )
91
90
92
91
XCTAssertTrue ( callbackExecuted)
93
92
let elapsedTime = Date ( ) . timeIntervalSince ( startTime)
94
- print ( " Elapsed time: \( elapsedTime) " )
95
93
#if !canImport(Darwin)
96
94
// FIXE: The elapsed time is somehow not correct on non-Darwin platform
97
95
throw XCTSkip ( " The elapsed time is somehow not correct on non-Darwin platform " )
@@ -101,26 +99,23 @@ final class TimerUtilsXCTests: XCTestCase {
101
99
102
100
func testWithDelayCanBeCancelled( ) async throws {
103
101
var callbackExecuted = false
104
- let timer = withDelay ( 0. 2) {
102
+ let timer = withDelay ( 2 ) {
105
103
callbackExecuted = true
106
104
}
107
105
XCTAssertTrue ( timer. isValid)
108
106
109
107
timer. invalidate ( )
110
- try await Task . sleep ( nanoseconds : 300_000_000 )
108
+ try await Task . sleep ( for : . seconds ( 5 ) )
111
109
XCTAssertFalse ( timer. isValid)
112
110
XCTAssertFalse ( callbackExecuted)
113
111
}
114
112
115
113
func testWithDelayRunsOnMainRunLoop( ) async throws {
116
- #if canImport(Darwin)
117
- throw XCTSkip ( " Skip flaky test case temporary " )
118
- #endif
119
114
let expectation = expectation ( description: " withDelay body call " )
120
- let _ = withDelay ( 0. 2) {
115
+ let _ = withDelay ( 2 ) {
121
116
XCTAssertTrue ( Thread . isMainThread)
122
117
expectation. fulfill ( )
123
118
}
124
- await fulfillment ( of: [ expectation] , timeout: 0.3 )
119
+ await fulfillment ( of: [ expectation] , timeout: 5 )
125
120
}
126
121
}
0 commit comments