Skip to content

Commit 199d2f8

Browse files
Merge pull request #3332 from SwiftPackageIndex/remove-wait-calls
Remove wait calls
2 parents fd972bf + 5c7d3e7 commit 199d2f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+633
-633
lines changed

Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
2525
func test_init_no_packageName() async throws {
2626
// Tests behaviour when we're lacking data
2727
// setup package without package name
28-
let pkg = try savePackage(on: app.db, "1".url)
28+
let pkg = try await savePackage(on: app.db, "1".url)
2929
try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db)
3030
let version = try App.Version(package: pkg,
3131
latest: .defaultBranch,
@@ -50,7 +50,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
5050
}
5151

5252
func test_init_packageIdentity() async throws {
53-
let pkg = try savePackage(on: app.db, URL(string: "https://github.com/foo/swift-bar.git")!)
53+
let pkg = try await savePackage(on: app.db, URL(string: "https://github.com/foo/swift-bar.git")!)
5454
try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db)
5555
let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main"))
5656
try await version.save(on: app.db)
@@ -71,7 +71,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
7171
}
7272

7373
func test_init_generated_documentation() async throws {
74-
let pkg = try savePackage(on: app.db, "1".url)
74+
let pkg = try await savePackage(on: app.db, "1".url)
7575
try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db)
7676
let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main"))
7777
version.docArchives = [.init(name: "archive1", title: "Archive One")]
@@ -93,7 +93,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
9393
}
9494

9595
func test_init_external_documentation() async throws {
96-
let pkg = try savePackage(on: app.db, "1".url)
96+
let pkg = try await savePackage(on: app.db, "1".url)
9797
try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db)
9898
let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main"))
9999
version.spiManifest = try .init(yml: """
@@ -454,7 +454,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
454454

455455
func test_languagePlatformInfo() async throws {
456456
// setup
457-
let pkg = try savePackage(on: app.db, "1")
457+
let pkg = try await savePackage(on: app.db, "1")
458458
try await Repository(package: pkg,
459459
defaultBranch: "default",
460460
name: "bar",

Tests/AppTests/API+PackageController+GetRouteTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class API_PackageController_GetRouteTests: AppTestCase {
2323

2424
func test_releaseInfo() async throws {
2525
// setup
26-
let pkg = try savePackage(on: app.db, "1")
26+
let pkg = try await savePackage(on: app.db, "1")
2727
try await Repository(package: pkg,
2828
defaultBranch: "default",
2929
name: "bar",
@@ -69,7 +69,7 @@ class API_PackageController_GetRouteTests: AppTestCase {
6969
func test_releaseInfo_exclude_non_latest() async throws {
7070
// Test to ensure that we don't include versions with `latest IS NULL`
7171
// setup
72-
let pkg = try savePackage(on: app.db, "1")
72+
let pkg = try await savePackage(on: app.db, "1")
7373
try await Repository(package: pkg,
7474
defaultBranch: "default",
7575
name: "bar",

Tests/AppTests/API+PackageControllerTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class API_PackageControllerTests: AppTestCase {
2727
Current.date = {
2828
Date.init(timeIntervalSince1970: 1608000588) // Dec 15, 2020
2929
}
30-
let pkg = try savePackage(on: app.db, "1")
30+
let pkg = try await savePackage(on: app.db, "1")
3131
try await Repository(package: pkg,
3232
commitCount: 1433,
3333
defaultBranch: "default",
@@ -65,7 +65,7 @@ class API_PackageControllerTests: AppTestCase {
6565
Current.date = {
6666
Date.init(timeIntervalSince1970: 1608000588) // Dec 15, 2020
6767
}
68-
let pkg = try savePackage(on: app.db, "1")
68+
let pkg = try await savePackage(on: app.db, "1")
6969
try await Repository(package: pkg,
7070
commitCount: 1433,
7171
defaultBranch: "default",
@@ -135,7 +135,7 @@ class API_PackageControllerTests: AppTestCase {
135135

136136
func test_ProductCount_query() async throws {
137137
// setup
138-
let pkg = try savePackage(on: app.db, "1")
138+
let pkg = try await savePackage(on: app.db, "1")
139139
try await Repository(package: pkg,
140140
defaultBranch: "main",
141141
name: "bar",
@@ -282,7 +282,7 @@ class API_PackageControllerTests: AppTestCase {
282282
func test_BuildInfo_query() async throws {
283283
// setup
284284
do {
285-
let pkg = try savePackage(on: app.db, "1".url)
285+
let pkg = try await savePackage(on: app.db, "1".url)
286286
try await Repository(package: pkg,
287287
defaultBranch: "main",
288288
name: "bar",
@@ -304,7 +304,7 @@ class API_PackageControllerTests: AppTestCase {
304304
}
305305
}
306306
do { // unrelated package and build
307-
let pkg = try savePackage(on: app.db, "2".url)
307+
let pkg = try await savePackage(on: app.db, "2".url)
308308
try await Repository(package: pkg,
309309
defaultBranch: "main",
310310
name: "bar2",
@@ -348,7 +348,7 @@ class API_PackageControllerTests: AppTestCase {
348348
func test_GetRoute_query() async throws {
349349
// ensure GetRoute.query is wired up correctly (detailed tests are elsewhere)
350350
// setup
351-
let pkg = try savePackage(on: app.db, "1")
351+
let pkg = try await savePackage(on: app.db, "1")
352352
try await Repository(package: pkg, name: "bar", owner: "foo")
353353
.save(on: app.db)
354354
try await Version(package: pkg, latest: .defaultBranch).save(on: app.db)

Tests/AppTests/API_DependencyControllerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class API_DependencyControllerTests: AppTestCase {
2121

2222
func test_query() async throws {
2323
// setup
24-
let pkg = try savePackage(on: app.db, id: .id0, "http://github.com/foo/bar")
24+
let pkg = try await savePackage(on: app.db, id: .id0, "http://github.com/foo/bar")
2525
try await Repository(package: pkg,
2626
defaultBranch: "default",
2727
name: "bar",

Tests/AppTests/AnalyzerTests.swift

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AnalyzerTests: AppTestCase {
3333
// expected shell commands for the happy path.)
3434
// setup
3535
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
36-
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
36+
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
3737
try await Repository(package: pkgs[0],
3838
defaultBranch: "main",
3939
name: "1",
@@ -300,7 +300,7 @@ class AnalyzerTests: AppTestCase {
300300
// Ensure a package that fails analysis goes back to ingesting and isn't stuck in an analysis loop
301301
// setup
302302
do {
303-
let pkg = try savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
303+
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
304304
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
305305
}
306306

@@ -337,7 +337,7 @@ class AnalyzerTests: AppTestCase {
337337
// Ensure packages record success/error status
338338
// setup
339339
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
340-
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
340+
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
341341
for p in pkgs {
342342
try await Repository(package: p, defaultBranch: "main").save(on: app.db)
343343
}
@@ -383,7 +383,7 @@ class AnalyzerTests: AppTestCase {
383383
// Test to ensure exceptions don't interrupt processing
384384
// setup
385385
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
386-
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
386+
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
387387
for p in pkgs {
388388
try await Repository(package: p, defaultBranch: "main").save(on: app.db)
389389
}
@@ -468,7 +468,7 @@ class AnalyzerTests: AppTestCase {
468468
@MainActor
469469
func test_refreshCheckout() async throws {
470470
// setup
471-
let pkg = try savePackage(on: app.db, "1".asGithubUrl.url)
471+
let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url)
472472
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
473473
Current.fileManager.fileExists = { @Sendable _ in true }
474474
let commands = QueueIsolated<[String]>([])
@@ -631,20 +631,20 @@ class AnalyzerTests: AppTestCase {
631631
.mock(description: "rel 2.3.0", publishedAt: 4, tagName: "2.3.0", url: "some url"),
632632
.mock(description: nil, tagName: "2.4.0")
633633
]).save(on: app.db)
634-
let versions: [Version] = try [
634+
let versions: [Version] = try await [
635635
(Date(timeIntervalSince1970: 0), Reference.tag(1, 2, 3)),
636636
(Date(timeIntervalSince1970: 1), Reference.tag(2, 0, 0)),
637637
(Date(timeIntervalSince1970: 2), Reference.tag(2, 1, 0)),
638638
(Date(timeIntervalSince1970: 3), Reference.tag(2, 2, 0)),
639639
(Date(timeIntervalSince1970: 4), Reference.tag(2, 3, 0)),
640640
(Date(timeIntervalSince1970: 5), Reference.tag(2, 4, 0)),
641641
(Date(timeIntervalSince1970: 6), Reference.branch("main")),
642-
].map { date, ref in
642+
].mapAsync { date, ref in
643643
let v = try Version(id: UUID(),
644644
package: pkg,
645645
commitDate: date,
646646
reference: ref)
647-
try v.save(on: app.db).wait()
647+
try await v.save(on: app.db)
648648
return v
649649
}
650650
let jpr = try await Package.fetchCandidate(app.db, id: .id0)
@@ -729,7 +729,7 @@ class AnalyzerTests: AppTestCase {
729729
}
730730
return ""
731731
}
732-
let pkg = try savePackage(on: app.db, "https://github.com/foo/1")
732+
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1")
733733
try await Repository(package: pkg, name: "1", owner: "foo").save(on: app.db)
734734
let version = try Version(id: UUID(), package: pkg, reference: .tag(.init(0, 4, 2)))
735735
try await version.save(on: app.db)
@@ -829,7 +829,7 @@ class AnalyzerTests: AppTestCase {
829829

830830
func test_updatePackages() async throws {
831831
// setup
832-
let packages = try savePackages(on: app.db, ["1", "2"].asURLs)
832+
let packages = try await savePackages(on: app.db, ["1", "2"].asURLs)
833833
.map(Joined<Package, Repository>.init(model:))
834834
let results: [Result<Joined<Package, Repository>, Error>] = [
835835
// feed in one error to see it passed through
@@ -894,9 +894,9 @@ class AnalyzerTests: AppTestCase {
894894
}
895895
return ""
896896
}
897-
let pkgs = try savePackages(on: app.db, ["1", "2"].asGithubUrls.asURLs, processingStage: .ingestion)
898-
try pkgs.forEach {
899-
try Repository(package: $0, defaultBranch: "main").save(on: app.db).wait()
897+
let pkgs = try await savePackages(on: app.db, ["1", "2"].asGithubUrls.asURLs, processingStage: .ingestion)
898+
for pkg in pkgs {
899+
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
900900
}
901901

902902
// MUT
@@ -907,16 +907,17 @@ class AnalyzerTests: AppTestCase {
907907
// validation
908908
// 1 version for the default branch + 2 for the tags each = 6 versions
909909
// 2 products per version = 12 products
910-
XCTAssertEqual(try Version.query(on: app.db).count().wait(), 6)
911-
XCTAssertEqual(try Product.query(on: app.db).count().wait(), 12)
910+
let db = app.db
911+
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 6)
912+
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 12)
912913
}
913914

914915
@MainActor
915916
func test_issue_70() async throws {
916917
// Certain git commands fail when index.lock exists
917918
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/70
918919
// setup
919-
try savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
920+
try await savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
920921
let pkgs = try await Package.fetchCandidates(app.db, for: .analysis, limit: 10)
921922

922923
let checkoutDir = Current.fileManager.checkoutsDirectory()
@@ -950,7 +951,7 @@ class AnalyzerTests: AppTestCase {
950951
// git checkout can still fail despite git reset --hard + git clean
951952
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/498
952953
// setup
953-
try savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
954+
try await savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
954955
let pkgs = try await Package.fetchCandidates(app.db, for: .analysis, limit: 10)
955956

956957
let checkoutDir = Current.fileManager.checkoutsDirectory()
@@ -1106,7 +1107,7 @@ class AnalyzerTests: AppTestCase {
11061107
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/693
11071108
// setup
11081109
do {
1109-
let pkg = try savePackage(on: app.db, id: .id0, "1".asGithubUrl.url)
1110+
let pkg = try await savePackage(on: app.db, id: .id0, "1".asGithubUrl.url)
11101111
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
11111112
}
11121113
let pkg = try await Package.fetchCandidate(app.db, id: .id0)
@@ -1455,7 +1456,7 @@ class AnalyzerTests: AppTestCase {
14551456
// Ensure we preserve dependency counts from previous default branch version
14561457
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2873
14571458
// setup
1458-
let pkg = try await savePackageAsync(on: app.db, id: .id0, "https://github.com/foo/1".url, processingStage: .ingestion)
1459+
let pkg = try await savePackage(on: app.db, id: .id0, "https://github.com/foo/1".url, processingStage: .ingestion)
14591460
try await Repository(package: pkg,
14601461
defaultBranch: "main",
14611462
name: "1",

0 commit comments

Comments
 (0)