Skip to content

Commit c381eef

Browse files
author
Rick Pasetto
authored
Misc unit test fixes (#410)
* Misc unit test fixes This fixes unit test failures that I regularly see locally, not sure why CI doesn't see it. Maybe my laptop runs faster? * Added comments
1 parent f2964b2 commit c381eef

File tree

3 files changed

+73
-39
lines changed

3 files changed

+73
-39
lines changed

LoopTests/Managers/Alerts/AlertStoreTests.swift

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AlertStoreTests: XCTestCase {
1515

1616
var alertStore: AlertStore!
1717

18+
static let defaultTimeout: TimeInterval = 1.5
1819
static let expiryInterval: TimeInterval = 24 /* hours */ * 60 /* minutes */ * 60 /* seconds */
1920
static let historicDate = Date(timeIntervalSinceNow: -expiryInterval + TimeInterval.hours(4)) // Within default 24 hour expiration
2021

@@ -100,7 +101,7 @@ class AlertStoreTests: XCTestCase {
100101
expect.fulfill()
101102
})
102103
})
103-
wait(for: [expect], timeout: 1)
104+
wait(for: [expect], timeout: Self.defaultTimeout)
104105
}
105106

106107
func testRecordIssuedTwo() {
@@ -113,7 +114,7 @@ class AlertStoreTests: XCTestCase {
113114
})
114115
})
115116
})
116-
wait(for: [expect], timeout: 1)
117+
wait(for: [expect], timeout: Self.defaultTimeout)
117118
}
118119

119120
func testRecordAcknowledged() {
@@ -132,7 +133,7 @@ class AlertStoreTests: XCTestCase {
132133
})
133134
})
134135
})
135-
wait(for: [expect], timeout: 1)
136+
wait(for: [expect], timeout: Self.defaultTimeout)
136137
}
137138

138139
func testRecordAcknowledgedOfInvalid() {
@@ -144,7 +145,7 @@ class AlertStoreTests: XCTestCase {
144145
}
145146
expect.fulfill()
146147
}
147-
wait(for: [expect], timeout: 1)
148+
wait(for: [expect], timeout: Self.defaultTimeout)
148149
}
149150

150151
func testRecordRetracted() {
@@ -163,7 +164,7 @@ class AlertStoreTests: XCTestCase {
163164
})
164165
})
165166
})
166-
wait(for: [expect], timeout: 1)
167+
wait(for: [expect], timeout: Self.defaultTimeout)
167168
}
168169

169170
func testRecordIssuedExpiresOld() {
@@ -180,7 +181,7 @@ class AlertStoreTests: XCTestCase {
180181
})
181182
})
182183
})
183-
wait(for: [expect], timeout: 1)
184+
wait(for: [expect], timeout: Self.defaultTimeout)
184185
}
185186

186187
func testRecordAcknowledgedExpiresOld() {
@@ -203,7 +204,7 @@ class AlertStoreTests: XCTestCase {
203204
})
204205
})
205206
})
206-
wait(for: [expect], timeout: 1)
207+
wait(for: [expect], timeout: Self.defaultTimeout)
207208
}
208209

209210
func testRecordRetractedBeforeRepeatDelayShouldDelete() {
@@ -218,7 +219,7 @@ class AlertStoreTests: XCTestCase {
218219
})
219220
})
220221
})
221-
wait(for: [expect], timeout: 1)
222+
wait(for: [expect], timeout: Self.defaultTimeout)
222223
}
223224

224225
func testRecordRetractedExactlyAtDelayShouldDelete() {
@@ -233,7 +234,7 @@ class AlertStoreTests: XCTestCase {
233234
})
234235
})
235236
})
236-
wait(for: [expect], timeout: 1)
237+
wait(for: [expect], timeout: Self.defaultTimeout)
237238
}
238239

239240
func testRecordRetractedExactlyAtRepeatDelayShouldDelete() {
@@ -248,7 +249,7 @@ class AlertStoreTests: XCTestCase {
248249
})
249250
})
250251
})
251-
wait(for: [expect], timeout: 1)
252+
wait(for: [expect], timeout: Self.defaultTimeout)
252253
}
253254

254255

@@ -268,7 +269,7 @@ class AlertStoreTests: XCTestCase {
268269
})
269270
})
270271
})
271-
wait(for: [expect], timeout: 1)
272+
wait(for: [expect], timeout: Self.defaultTimeout)
272273
}
273274

274275
func testRecordRetractedAfterRepeatDelayShouldRetract() {
@@ -287,7 +288,7 @@ class AlertStoreTests: XCTestCase {
287288
})
288289
})
289290
})
290-
wait(for: [expect], timeout: 1)
291+
wait(for: [expect], timeout: Self.defaultTimeout)
291292
}
292293

293294
// These next two tests are admittedly weird corner cases, but theoretically they might be race conditions,
@@ -311,7 +312,7 @@ class AlertStoreTests: XCTestCase {
311312
})
312313
})
313314
})
314-
wait(for: [expect], timeout: 1)
315+
wait(for: [expect], timeout: Self.defaultTimeout)
315316
}
316317

317318
func testRecordAcknowledgedThenRetracted() {
@@ -333,7 +334,7 @@ class AlertStoreTests: XCTestCase {
333334
})
334335
})
335336
})
336-
wait(for: [expect], timeout: 1)
337+
wait(for: [expect], timeout: Self.defaultTimeout)
337338
}
338339

339340
func testEmptyQuery() {
@@ -344,7 +345,7 @@ class AlertStoreTests: XCTestCase {
344345
expect.fulfill()
345346
})
346347
})
347-
wait(for: [expect], timeout: 1)
348+
wait(for: [expect], timeout: Self.defaultTimeout)
348349
}
349350

350351
func testSimpleQuery() {
@@ -360,7 +361,7 @@ class AlertStoreTests: XCTestCase {
360361
expect.fulfill()
361362
})
362363
})
363-
wait(for: [expect], timeout: 1)
364+
wait(for: [expect], timeout: Self.defaultTimeout)
364365
}
365366

366367
func testSimpleQueryThenRetraction() {
@@ -388,7 +389,7 @@ class AlertStoreTests: XCTestCase {
388389
})
389390
})
390391
})
391-
wait(for: [expect], timeout: 1)
392+
wait(for: [expect], timeout: Self.defaultTimeout)
392393
}
393394

394395
func testQueryByDate() {
@@ -407,7 +408,7 @@ class AlertStoreTests: XCTestCase {
407408
})
408409
})
409410
})
410-
wait(for: [expect], timeout: 1)
411+
wait(for: [expect], timeout: Self.defaultTimeout)
411412
}
412413

413414
func testQueryByDateExcludingFutureDelayed() {
@@ -426,7 +427,7 @@ class AlertStoreTests: XCTestCase {
426427
})
427428
})
428429
})
429-
wait(for: [expect], timeout: 1)
430+
wait(for: [expect], timeout: Self.defaultTimeout)
430431
}
431432

432433
func testQueryByDateExcludingFutureRepeating() {
@@ -445,7 +446,7 @@ class AlertStoreTests: XCTestCase {
445446
})
446447
})
447448
})
448-
wait(for: [expect], timeout: 1)
449+
wait(for: [expect], timeout: Self.defaultTimeout)
449450
}
450451

451452
func testQueryByDateNotExcludingFutureDelayed() {
@@ -460,7 +461,7 @@ class AlertStoreTests: XCTestCase {
460461
})
461462
})
462463
})
463-
wait(for: [expect], timeout: 1)
464+
wait(for: [expect], timeout: Self.defaultTimeout)
464465
}
465466

466467
func testQueryWithLimit() {
@@ -478,7 +479,7 @@ class AlertStoreTests: XCTestCase {
478479
})
479480
})
480481
})
481-
wait(for: [expect], timeout: 1)
482+
wait(for: [expect], timeout: Self.defaultTimeout)
482483
}
483484

484485
func testQueryThenContinue() {
@@ -499,7 +500,7 @@ class AlertStoreTests: XCTestCase {
499500
})
500501
})
501502
})
502-
wait(for: [expect], timeout: 1)
503+
wait(for: [expect], timeout: Self.defaultTimeout)
503504
}
504505

505506
func testAcknowledgeFindsCorrectOne() {
@@ -525,7 +526,7 @@ class AlertStoreTests: XCTestCase {
525526
})
526527
})
527528
}
528-
wait(for: [expect], timeout: 1)
529+
wait(for: [expect], timeout: Self.defaultTimeout)
529530
}
530531

531532
func testAcknowledgeMultiple() {
@@ -547,7 +548,7 @@ class AlertStoreTests: XCTestCase {
547548
})
548549
})
549550
}
550-
wait(for: [expect], timeout: 1)
551+
wait(for: [expect], timeout: Self.defaultTimeout)
551552
}
552553

553554
func testLookupAllUnacknowledgedEmpty() {
@@ -556,7 +557,7 @@ class AlertStoreTests: XCTestCase {
556557
XCTAssertTrue(alerts.isEmpty)
557558
expect.fulfill()
558559
})
559-
wait(for: [expect], timeout: 1)
560+
wait(for: [expect], timeout: Self.defaultTimeout)
560561
}
561562

562563
func testLookupAllUnacknowledgedOne() {
@@ -567,7 +568,7 @@ class AlertStoreTests: XCTestCase {
567568
expect.fulfill()
568569
})
569570
}
570-
wait(for: [expect], timeout: 1)
571+
wait(for: [expect], timeout: Self.defaultTimeout)
571572
}
572573

573574

@@ -579,7 +580,7 @@ class AlertStoreTests: XCTestCase {
579580
expect.fulfill()
580581
})
581582
}
582-
wait(for: [expect], timeout: 1)
583+
wait(for: [expect], timeout: Self.defaultTimeout)
583584
}
584585

585586
func testLookupAllUnacknowledgedSomeNot() {
@@ -594,7 +595,7 @@ class AlertStoreTests: XCTestCase {
594595
expect.fulfill()
595596
})
596597
}
597-
wait(for: [expect], timeout: 1)
598+
wait(for: [expect], timeout: Self.defaultTimeout)
598599
}
599600

600601
func testLookupAllUnacknowledgedSomeRetracted() {
@@ -609,7 +610,7 @@ class AlertStoreTests: XCTestCase {
609610
expect.fulfill()
610611
})
611612
}
612-
wait(for: [expect], timeout: 1)
613+
wait(for: [expect], timeout: Self.defaultTimeout)
613614
}
614615

615616
func testLookupAllAcknowledgedUnretractedRepeatingAlertsAll() {
@@ -624,7 +625,7 @@ class AlertStoreTests: XCTestCase {
624625
expect.fulfill()
625626
})
626627
}
627-
wait(for: [expect], timeout: 1)
628+
wait(for: [expect], timeout: Self.defaultTimeout)
628629
}
629630

630631
func testLookupAllAcknowledgedUnretractedRepeatingAlertsEmpty() {
@@ -633,7 +634,7 @@ class AlertStoreTests: XCTestCase {
633634
XCTAssertTrue(alerts.isEmpty)
634635
expect.fulfill()
635636
})
636-
wait(for: [expect], timeout: 1)
637+
wait(for: [expect], timeout: Self.defaultTimeout)
637638
}
638639

639640
func testLookupAllAcknowledgedUnretractedRepeatingAlertsSome() {
@@ -649,7 +650,7 @@ class AlertStoreTests: XCTestCase {
649650
expect.fulfill()
650651
})
651652
}
652-
wait(for: [expect], timeout: 1)
653+
wait(for: [expect], timeout: Self.defaultTimeout)
653654
}
654655

655656

0 commit comments

Comments
 (0)