Skip to content

Commit 797ea8f

Browse files
committed
Remove all remaining wait() calls
1 parent 8127161 commit 797ea8f

File tree

5 files changed

+128
-115
lines changed

5 files changed

+128
-115
lines changed

Tests/AppTests/AnalyzerVersionThrottlingTests.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import XCTest
1919

2020
class AnalyzerVersionThrottlingTests: AppTestCase {
2121

22-
func test_throttle_keep_old() throws {
22+
func test_throttle_keep_old() async throws {
2323
// Test keeping old when within throttling window
2424
// setup
2525
Current.date = { .t0 }
2626
let pkg = Package(url: "1")
27-
try pkg.save(on: app.db).wait()
27+
try await pkg.save(on: app.db)
2828
let old = try makeVersion(pkg, "sha_old", -.hours(23), .branch("main"))
2929
let new = try makeVersion(pkg, "sha_new", -.hours(1), .branch("main"))
3030

@@ -35,12 +35,12 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
3535
XCTAssertEqual(res, [old])
3636
}
3737

38-
func test_throttle_take_new() throws {
38+
func test_throttle_take_new() async throws {
3939
// Test picking new version when old one is outside the window
4040
// setup
4141
Current.date = { .t0 }
4242
let pkg = Package(url: "1")
43-
try pkg.save(on: app.db).wait()
43+
try await pkg.save(on: app.db)
4444
let old = try makeVersion(pkg, "sha_old", .hours(-26), .branch("main"))
4545
let new = try makeVersion(pkg, "sha_new", .hours(-1), .branch("main"))
4646

@@ -51,12 +51,12 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
5151
XCTAssertEqual(res, [new])
5252
}
5353

54-
func test_throttle_ignore_tags() throws {
54+
func test_throttle_ignore_tags() async throws {
5555
// Test to ensure tags are exempt from throttling
5656
// setup
5757
Current.date = { .t0 }
5858
let pkg = Package(url: "1")
59-
try pkg.save(on: app.db).wait()
59+
try await pkg.save(on: app.db)
6060
let old = try makeVersion(pkg, "sha_old", .hours(-23), .tag(1, 0, 0))
6161
let new = try makeVersion(pkg, "sha_new", .hours(-1), .tag(2, 0, 0))
6262

@@ -67,12 +67,12 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
6767
XCTAssertEqual(res, [new])
6868
}
6969

70-
func test_throttle_new_package() throws {
70+
func test_throttle_new_package() async throws {
7171
// Test picking up a new package's branch
7272
// setup
7373
Current.date = { .t0 }
7474
let pkg = Package(url: "1")
75-
try pkg.save(on: app.db).wait()
75+
try await pkg.save(on: app.db)
7676
let new = try makeVersion(pkg, "sha_new", .hours(-1), .branch("main"))
7777

7878
// MUT
@@ -82,14 +82,14 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
8282
XCTAssertEqual(res, [new])
8383
}
8484

85-
func test_throttle_branch_ref_change() throws {
85+
func test_throttle_branch_ref_change() async throws {
8686
// Test behaviour when changing default branch names
8787
// Changed to return [new] to avoid branch renames causing 404s
8888
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2217
8989
// setup
9090
Current.date = { .t0 }
9191
let pkg = Package(url: "1")
92-
try pkg.save(on: app.db).wait()
92+
try await pkg.save(on: app.db)
9393
let old = try makeVersion(pkg, "sha_old", .hours(-23), .branch("develop"))
9494
let new = try makeVersion(pkg, "sha_new", .hours(-1), .branch("main"))
9595

@@ -100,14 +100,14 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
100100
XCTAssertEqual(res, [new])
101101
}
102102

103-
func test_throttle_rename() throws {
103+
func test_throttle_rename() async throws {
104104
// Ensure incoming branch renames are throttled
105105
// Changed to return [new] to avoid branch renames causing 404s
106106
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2217
107107
// setup
108108
Current.date = { .t0 }
109109
let pkg = Package(url: "1")
110-
try pkg.save(on: app.db).wait()
110+
try await pkg.save(on: app.db)
111111
let old = try makeVersion(pkg, "sha", .hours(-1), .branch("main-old"))
112112
let new = try makeVersion(pkg, "sha", .hours(-1), .branch("main-new"))
113113

@@ -118,14 +118,14 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
118118
XCTAssertEqual(res, [new])
119119
}
120120

121-
func test_throttle_multiple_incoming_branches_keep_old() throws {
121+
func test_throttle_multiple_incoming_branches_keep_old() async throws {
122122
// Test behaviour with multiple incoming branch revisions
123123
// NB: this is a theoretical scenario, in practise there should only
124124
// ever be one branch revision among the incoming revisions.
125125
// setup
126126
Current.date = { .t0 }
127127
let pkg = Package(url: "1")
128-
try pkg.save(on: app.db).wait()
128+
try await pkg.save(on: app.db)
129129
let old = try makeVersion(pkg, "sha_old", .hours(-23), .branch("main"))
130130
let new0 = try makeVersion(pkg, "sha_new0", .hours(-3), .branch("main"))
131131
let new1 = try makeVersion(pkg, "sha_new1", .hours(-2), .branch("main"))
@@ -139,14 +139,14 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
139139
XCTAssertEqual(res, [old])
140140
}
141141

142-
func test_throttle_multiple_incoming_branches_take_new() throws {
142+
func test_throttle_multiple_incoming_branches_take_new() async throws {
143143
// Test behaviour with multiple incoming branch revisions
144144
// NB: this is a theoretical scenario, in practise there should only
145145
// ever be one branch revision among the incoming revisions.
146146
// setup
147147
Current.date = { .t0 }
148148
let pkg = Package(url: "1")
149-
try pkg.save(on: app.db).wait()
149+
try await pkg.save(on: app.db)
150150
let old = try makeVersion(pkg, "sha_old", .hours(-26), .branch("main"))
151151
let new0 = try makeVersion(pkg, "sha_new0", .hours(-3), .branch("main"))
152152
let new1 = try makeVersion(pkg, "sha_new1", .hours(-2), .branch("main"))
@@ -287,7 +287,7 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
287287
}
288288
}
289289

290-
func test_throttle_force_push() throws {
290+
func test_throttle_force_push() async throws {
291291
// Test the exceptional case where we have a newer branch revision in
292292
// the db than the incoming version. This could happen for instance
293293
// if an older branch revision is force pushed, effectively removing
@@ -296,7 +296,7 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
296296
// setup
297297
Current.date = { .t0 }
298298
let pkg = Package(url: "1")
299-
try pkg.save(on: app.db).wait()
299+
try await pkg.save(on: app.db)
300300

301301
do { // both within window
302302
let ex = try makeVersion(pkg, "sha-ex", .hours(-1), .branch("main"))

Tests/AppTests/BuildTriggerTests.swift

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,36 @@ class BuildTriggerTests: AppTestCase {
4242
latest: .defaultBranch,
4343
reference: .branch("main"))
4444
try await v.save(on: app.db)
45-
try BuildPair.all.forEach { pair in
46-
try Build(id: UUID(),
47-
version: v,
48-
platform: pair.platform,
49-
status: .ok,
50-
swiftVersion: pair.swiftVersion)
51-
.save(on: app.db).wait()
45+
for pair in BuildPair.all {
46+
try await Build(id: UUID(),
47+
version: v,
48+
platform: pair.platform,
49+
status: .ok,
50+
swiftVersion: pair.swiftVersion)
51+
.save(on: app.db)
5252
}
5353
}
5454
// save two packages with partially completed builds
55-
try [pkgIdIncomplete1, pkgIdIncomplete2].forEach { id in
55+
for id in [pkgIdIncomplete1, pkgIdIncomplete2] {
5656
let p = Package(id: id, url: id.uuidString.url)
57-
try p.save(on: app.db).wait()
58-
try [Version.Kind.defaultBranch, .release].forEach { kind in
57+
try await p.save(on: app.db)
58+
for kind in [Version.Kind.defaultBranch, .release] {
5959
let v = try Version(package: p,
6060
latest: kind,
6161
reference: kind == .release
62-
? .tag(1, 2, 3)
63-
: .branch("main"))
64-
try v.save(on: app.db).wait()
65-
try BuildPair.all
62+
? .tag(1, 2, 3)
63+
: .branch("main"))
64+
try await v.save(on: app.db)
65+
for pair in BuildPair.all
6666
.dropFirst() // skip one platform to create a build gap
67-
.forEach { pair in
68-
try Build(id: UUID(),
69-
version: v,
70-
platform: pair.platform,
71-
status: .ok,
72-
swiftVersion: pair.swiftVersion)
73-
.save(on: app.db).wait()
74-
}
67+
{
68+
try await Build(id: UUID(),
69+
version: v,
70+
platform: pair.platform,
71+
status: .ok,
72+
swiftVersion: pair.swiftVersion)
73+
.save(on: app.db)
74+
}
7575
}
7676
}
7777

@@ -90,13 +90,13 @@ class BuildTriggerTests: AppTestCase {
9090
let pkgId = UUID()
9191
let p = Package(id: pkgId, url: pkgId.uuidString.url)
9292
try await p.save(on: app.db)
93-
try [Version.Kind.defaultBranch, .release].forEach { kind in
93+
for kind in [Version.Kind.defaultBranch, .release] {
9494
let v = try Version(package: p,
9595
latest: kind,
9696
reference: kind == .release
97-
? .tag(1, 2, 3)
98-
: .branch("main"))
99-
try v.save(on: app.db).wait()
97+
? .tag(1, 2, 3)
98+
: .branch("main"))
99+
try await v.save(on: app.db)
100100
}
101101

102102
// MUT
@@ -157,26 +157,26 @@ class BuildTriggerTests: AppTestCase {
157157
let pkgIdIncomplete2 = UUID()
158158
Current.buildTriggerAllowList = { [pkgIdIncomplete2] }
159159
// save two packages with partially completed builds
160-
try [pkgIdIncomplete1, pkgIdIncomplete2].forEach { id in
160+
for id in [pkgIdIncomplete1, pkgIdIncomplete2] {
161161
let p = Package(id: id, url: id.uuidString.url)
162-
try p.save(on: app.db).wait()
163-
try [Version.Kind.defaultBranch, .release].forEach { kind in
162+
try await p.save(on: app.db)
163+
for kind in [Version.Kind.defaultBranch, .release] {
164164
let v = try Version(package: p,
165165
latest: kind,
166166
reference: kind == .release
167167
? .tag(1, 2, 3)
168168
: .branch("main"))
169-
try v.save(on: app.db).wait()
170-
try BuildPair.all
169+
try await v.save(on: app.db)
170+
for pair in BuildPair.all
171171
.dropFirst() // skip one platform to create a build gap
172-
.forEach { pair in
173-
try Build(id: UUID(),
174-
version: v,
175-
platform: pair.platform,
176-
status: .ok,
177-
swiftVersion: pair.swiftVersion)
178-
.save(on: app.db).wait()
179-
}
172+
{
173+
try await Build(id: UUID(),
174+
version: v,
175+
platform: pair.platform,
176+
status: .ok,
177+
swiftVersion: pair.swiftVersion)
178+
.save(on: app.db)
179+
}
180180
}
181181
}
182182

@@ -213,16 +213,16 @@ class BuildTriggerTests: AppTestCase {
213213
latest: .release,
214214
reference: .tag(1, 2, 3))
215215
try await v.save(on: app.db)
216-
try Build.Platform.allActive
217-
.filter { $0 != droppedPlatform } // skip one platform to create a build gap
218-
.forEach { platform in
219-
try SwiftVersion.allActive.forEach { swiftVersion in
220-
try Build(id: UUID(),
221-
version: v,
222-
platform: platform,
223-
status: .ok,
224-
swiftVersion: swiftVersion)
225-
.save(on: app.db).wait()
216+
for platform in Build.Platform.allActive
217+
.filter({ $0 != droppedPlatform }) // skip one platform to create a build gap
218+
{
219+
for swiftVersion in SwiftVersion.allActive {
220+
try await Build(id: UUID(),
221+
version: v,
222+
platform: platform,
223+
status: .ok,
224+
swiftVersion: swiftVersion)
225+
.save(on: app.db)
226226
}
227227
}
228228
}
@@ -303,16 +303,16 @@ class BuildTriggerTests: AppTestCase {
303303
- documentation_targets: [t0]
304304
"""))
305305
try await v.save(on: app.db)
306-
try Build.Platform.allActive
307-
.filter { $0 != .macosSpm } // skip macosSpm platform to create a build gap
308-
.forEach { platform in
309-
try SwiftVersion.allActive.forEach { swiftVersion in
310-
try Build(id: UUID(),
311-
version: v,
312-
platform: platform,
313-
status: .ok,
314-
swiftVersion: swiftVersion)
315-
.save(on: app.db).wait()
306+
for platform in Build.Platform.allActive
307+
.filter({ $0 != .macosSpm }) // skip macosSpm platform to create a build gap
308+
{
309+
for swiftVersion in SwiftVersion.allActive {
310+
try await Build(id: UUID(),
311+
version: v,
312+
platform: platform,
313+
status: .ok,
314+
swiftVersion: swiftVersion)
315+
.save(on: app.db)
316316
}
317317
}
318318
}
@@ -671,11 +671,11 @@ class BuildTriggerTests: AppTestCase {
671671
Current.getStatusCount = { c, _ in 299 + triggerCount.withLockedValue { $0 } }
672672

673673
let pkgIds = [UUID(), UUID()]
674-
try pkgIds.forEach { id in
674+
for id in pkgIds {
675675
let p = Package(id: id, url: id.uuidString.url)
676-
try p.save(on: app.db).wait()
677-
try Version(id: UUID(), package: p, latest: .defaultBranch, reference: .branch("main"))
678-
.save(on: app.db).wait()
676+
try await p.save(on: app.db)
677+
try await Version(id: UUID(), package: p, latest: .defaultBranch, reference: .branch("main"))
678+
.save(on: app.db)
679679
}
680680

681681
// MUT
@@ -705,7 +705,8 @@ class BuildTriggerTests: AppTestCase {
705705
.save(on: app.db)
706706
// shift createdAt back to make build eligible from trimming
707707
try await updateBuildCreatedAt(id: .id2, addTimeInterval: -.hours(5), on: app.db)
708-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 1)
708+
let db = app.db
709+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 1)
709710

710711
// MUT
711712
try await triggerBuilds(on: app.db,
@@ -1019,7 +1020,8 @@ class BuildTriggerTests: AppTestCase {
10191020
try await updateBuildCreatedAt(id: .id2, addTimeInterval: -.hours(5), on: app.db)
10201021
}
10211022

1022-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 3)
1023+
let db = app.db
1024+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 3)
10231025

10241026
// MUT
10251027
let deleteCount = try await trimBuilds(on: app.db)
@@ -1055,7 +1057,8 @@ class BuildTriggerTests: AppTestCase {
10551057
try await updateBuildCreatedAt(id: .id2, addTimeInterval: -.hours(5), on: app.db)
10561058
}
10571059

1058-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 3)
1060+
let db = app.db
1061+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 3)
10591062

10601063
// MUT
10611064
let deleteCount = try await trimBuilds(on: app.db)
@@ -1111,7 +1114,8 @@ class BuildTriggerTests: AppTestCase {
11111114
}
11121115
}
11131116

1114-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 8)
1117+
let db = app.db
1118+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 8)
11151119

11161120
// MUT
11171121
let deleteCount = try await trimBuilds(on: app.db)
@@ -1167,7 +1171,8 @@ class BuildTriggerTests: AppTestCase {
11671171

11681172
// validate
11691173
XCTAssertEqual(deleteCount, 0)
1170-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 1)
1174+
let db = app.db
1175+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 1)
11711176

11721177
// make build "old" by resetting "created_at"
11731178
try await updateBuildCreatedAt(id: buildId, addTimeInterval: -.hours(4), on: app.db)
@@ -1202,7 +1207,8 @@ class BuildTriggerTests: AppTestCase {
12021207

12031208
// validate
12041209
XCTAssertEqual(deleteCount, 0)
1205-
XCTAssertEqual(try Build.query(on: app.db).count().wait(), 1)
1210+
let db = app.db
1211+
try await XCTAssertEqualAsync(try await Build.query(on: db).count(), 1)
12061212

12071213
// make build "old" by resetting "created_at"
12081214
try await updateBuildCreatedAt(id: buildId, addTimeInterval: -.hours(5), on: app.db)

0 commit comments

Comments
 (0)