Skip to content

Commit 1b3aef5

Browse files
committed
More swiftly test cleanup routines
Bump the default http client read timeout
1 parent 7979a66 commit 1b3aef5

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ public struct Linux: Platform {
361361
}
362362

363363
let tmpDir = self.getTempFilePath()
364+
defer {
365+
try? FileManager.default.removeItem(at: tmpDir)
366+
}
364367
try FileManager.default.createDirectory(atPath: tmpDir.path, withIntermediateDirectories: true)
365368

366369
ctx.print("Extracting new swiftly...")

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class HTTPRequestExecutorImpl: HTTPRequestExecutor {
124124
}
125125

126126
public func getCurrentSwiftlyRelease() async throws -> Components.Schemas.SwiftlyRelease {
127-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(45))
127+
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
128128
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
129129

130130
let client = Client(
@@ -138,7 +138,7 @@ public class HTTPRequestExecutorImpl: HTTPRequestExecutor {
138138
}
139139

140140
public func getReleaseToolchains() async throws -> [Components.Schemas.Release] {
141-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(45))
141+
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
142142
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
143143

144144
let client = Client(
@@ -153,7 +153,7 @@ public class HTTPRequestExecutorImpl: HTTPRequestExecutor {
153153
}
154154

155155
public func getSnapshotToolchains(branch: Components.Schemas.SourceBranch, platform: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
156-
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(45))
156+
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(60))
157157
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
158158

159159
let client = Client(
@@ -457,7 +457,7 @@ public struct SwiftlyHTTPClient {
457457
}
458458

459459
let request = makeRequest(url: url.absoluteString)
460-
let response = try await self.httpRequestExecutor.execute(request, timeout: .seconds(45))
460+
let response = try await self.httpRequestExecutor.execute(request, timeout: .seconds(60))
461461

462462
switch response.status {
463463
case .ok:

Tests/SwiftlyTests/PlatformTests.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44
import Testing
55

66
@Suite struct PlatformTests {
7-
func mockToolchainDownload(version: String) async throws -> (URL, ToolchainVersion) {
7+
func mockToolchainDownload(version: String) async throws -> (URL, ToolchainVersion, URL) {
88
let mockDownloader = MockToolchainDownloader(executables: ["swift"])
99
let version = try! ToolchainVersion(parsing: version)
1010
let ext = Swiftly.currentPlatform.toolchainFileExtension
@@ -14,28 +14,37 @@ import Testing
1414
let mockedToolchain = try mockDownloader.makeMockedToolchain(toolchain: version, name: tmpDir.path)
1515
try mockedToolchain.write(to: mockedToolchainFile)
1616

17-
return (mockedToolchainFile, version)
17+
return (mockedToolchainFile, version, tmpDir)
1818
}
1919

2020
@Test(.testHome()) func install() async throws {
2121
// GIVEN: a toolchain has been downloaded
22-
var (mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.7.1")
22+
var (mockedToolchainFile, version, tmpDir) = try await self.mockToolchainDownload(version: "5.7.1")
23+
var cleanup = [tmpDir]
24+
defer {
25+
for dir in cleanup {
26+
try? FileManager.default.removeItem(at: dir)
27+
}
28+
}
29+
2330
// WHEN: the platform installs the toolchain
2431
try Swiftly.currentPlatform.install(SwiftlyTests.ctx, from: mockedToolchainFile, version: version, verbose: true)
2532
// THEN: the toolchain is extracted in the toolchains directory
2633
var toolchains = try FileManager.default.contentsOfDirectory(at: Swiftly.currentPlatform.swiftlyToolchainsDir(SwiftlyTests.ctx), includingPropertiesForKeys: nil)
2734
#expect(1 == toolchains.count)
2835

2936
// GIVEN: a second toolchain has been downloaded
30-
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
37+
(mockedToolchainFile, version, tmpDir) = try await self.mockToolchainDownload(version: "5.8.0")
38+
cleanup += [tmpDir]
3139
// WHEN: the platform installs the toolchain
3240
try Swiftly.currentPlatform.install(SwiftlyTests.ctx, from: mockedToolchainFile, version: version, verbose: true)
3341
// THEN: the toolchain is added to the toolchains directory
3442
toolchains = try FileManager.default.contentsOfDirectory(at: Swiftly.currentPlatform.swiftlyToolchainsDir(SwiftlyTests.ctx), includingPropertiesForKeys: nil)
3543
#expect(2 == toolchains.count)
3644

3745
// GIVEN: an identical toolchain has been downloaded
38-
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
46+
(mockedToolchainFile, version, tmpDir) = try await self.mockToolchainDownload(version: "5.8.0")
47+
cleanup += [tmpDir]
3948
// WHEN: the platform installs the toolchain
4049
try Swiftly.currentPlatform.install(SwiftlyTests.ctx, from: mockedToolchainFile, version: version, verbose: true)
4150
// THEN: the toolchains directory remains the same
@@ -45,9 +54,16 @@ import Testing
4554

4655
@Test(.testHome()) func uninstall() async throws {
4756
// GIVEN: toolchains have been downloaded, and installed
48-
var (mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
57+
var (mockedToolchainFile, version, tmpDir) = try await self.mockToolchainDownload(version: "5.8.0")
58+
var cleanup = [tmpDir]
59+
defer {
60+
for dir in cleanup {
61+
try? FileManager.default.removeItem(at: dir)
62+
}
63+
}
4964
try Swiftly.currentPlatform.install(SwiftlyTests.ctx, from: mockedToolchainFile, version: version, verbose: true)
50-
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.6.3")
65+
(mockedToolchainFile, version, tmpDir) = try await self.mockToolchainDownload(version: "5.6.3")
66+
cleanup += [tmpDir]
5167
try Swiftly.currentPlatform.install(SwiftlyTests.ctx, from: mockedToolchainFile, version: version, verbose: true)
5268
// WHEN: one of the toolchains is uninstalled
5369
try Swiftly.currentPlatform.uninstall(SwiftlyTests.ctx, version, verbose: true)

0 commit comments

Comments
 (0)