Skip to content

Commit d0f06a6

Browse files
committed
Structure expectations so that package registry tests fail fast
1 parent 2e29ff6 commit d0f06a6

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

Tests/PackageRegistryTests/RegistryManagerTests.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ final class RegistryManagerTests: XCTestCase {
3434
XCTAssertResultSuccess(result)
3535
}
3636

37-
wait(for: [expectation], timeout: 10.0)
37+
self.wait(for: [expectation], timeout: 10.0)
3838
}
3939

4040
func testFetchVersions() {
4141
let package = PackageReference(identity: "github.com/mona/LinkedList".lowercased(), path: "/LinkedList")
4242
let expectation = XCTestExpectation(description: "discover package registry")
43-
let nestedExpectation = XCTestExpectation(description: "fetch versions")
4443

4544
RegistryManager.discover(for: package) { result in
4645
defer { expectation.fulfill() }
46+
47+
XCTAssertResultSuccess(result)
4748
guard case .success(let manager) = result else { return }
4849

50+
let nestedExpectation = XCTestExpectation(description: "fetch versions")
51+
4952
manager.fetchVersions(of: package) { result in
5053
defer { nestedExpectation.fulfill() }
5154

@@ -55,22 +58,27 @@ final class RegistryManagerTests: XCTestCase {
5558
XCTAssertEqual(versions, ["1.1.1", "1.0.0"])
5659
XCTAssertFalse(versions.contains("1.1.0"), "problematic releases shouldn't be included")
5760
}
61+
62+
self.wait(for: [nestedExpectation], timeout: 10.0)
5863
}
5964

60-
wait(for: [expectation, nestedExpectation], timeout: 10.0)
65+
self.wait(for: [expectation], timeout: 10.0)
6166
}
6267

6368
func testFetchManifest() {
6469
let package = PackageReference(identity: "github.com/mona/LinkedList".lowercased(), path: "/LinkedList")
6570
let expectation = XCTestExpectation(description: "discover package registry")
66-
let nestedExpectation = XCTestExpectation(description: "fetch manifest")
6771

6872
RegistryManager.discover(for: package) { result in
6973
defer { expectation.fulfill() }
74+
75+
XCTAssertResultSuccess(result)
7076
guard case .success(let manager) = result else { return }
7177

7278
let manifestLoader = ManifestLoader(manifestResources: Resources.default)
7379

80+
let nestedExpectation = XCTestExpectation(description: "fetch manifest")
81+
7482
manager.fetchManifest(for: "1.1.1", of: package, using: manifestLoader) { result in
7583
defer { nestedExpectation.fulfill() }
7684

@@ -91,22 +99,28 @@ final class RegistryManagerTests: XCTestCase {
9199

92100
XCTAssertEqual(manifest.swiftLanguageVersions, [.v4, .v5])
93101
}
102+
103+
self.wait(for: [nestedExpectation], timeout: 10.0)
94104
}
95105

96-
wait(for: [expectation, nestedExpectation], timeout: 10.0)
106+
self.wait(for: [expectation], timeout: 10.0)
97107
}
98108

99109
func testDownloadSourceArchive() {
100110
let package = PackageReference(identity: "github.com/mona/LinkedList".lowercased(), path: "/LinkedList")
101111
let expectation = XCTestExpectation(description: "discover package registry")
102-
let nestedExpectation = XCTestExpectation(description: "fetch manifest")
103112

104113
RegistryManager.discover(for: package) { result in
105114
defer { expectation.fulfill() }
115+
116+
XCTAssertResultSuccess(result)
106117
guard case .success(let manager) = result else { return }
107118

108119
let fs = InMemoryFileSystem()
109120
let path = AbsolutePath("/LinkedList-1.1.1.zip")
121+
122+
let nestedExpectation = XCTestExpectation(description: "fetch manifest")
123+
110124
manager.downloadSourceArchive(for: "1.1.1", of: package, into: fs, at: path) { result in
111125
defer { nestedExpectation.fulfill() }
112126

@@ -118,8 +132,10 @@ final class RegistryManagerTests: XCTestCase {
118132
XCTAssertEqual(data, emptyZipFile)
119133
}
120134
}
135+
136+
self.wait(for: [nestedExpectation], timeout: 10.0)
121137
}
122138

123-
wait(for: [expectation, nestedExpectation], timeout: 10.0)
139+
self.wait(for: [expectation], timeout: 10.0)
124140
}
125141
}

0 commit comments

Comments
 (0)