Skip to content

Commit 3cf2c6a

Browse files
authored
Fix unstable integration tests. (apple#1060)
- TestCLIRunCommand now run so many tests concurrently that the API server gets swamped and tests randomly time out. - The parallelism options on `swift test` only work for XCTest, not swift-testing. - Work around this while retaining some parallelism (good for stress testing) by breaking the tests into two suites.
1 parent 8897fcc commit 3cf2c6a

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ integration: init-block
184184
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunLifecycle || exit_code=1 ; \
185185
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIExecCommand || exit_code=1 ; \
186186
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLICreateCommand || exit_code=1 ; \
187-
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand || exit_code=1 ; \
187+
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand1 || exit_code=1 ; \
188+
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand2 || exit_code=1 ; \
188189
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIStatsCommand || exit_code=1 ; \
189190
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIImagesCommand || exit_code=1 ; \
190191
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunBase || exit_code=1 ; \

Tests/CLITests/Subcommands/Run/TestCLIRunCommand.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ import ContainerizationOS
2121
import Foundation
2222
import Testing
2323

24-
class TestCLIRunCommand: CLITest {
25-
private func getTestName() -> String {
24+
// FIXME: We've split the tests into two suites to prevent swamping
25+
// the API server with so many run commands that all wind up pulling
26+
// images.
27+
//
28+
// When https://github.com/swiftlang/swift-testing/pull/1390 lands
29+
// and is available on the CI runners, we can try setting the
30+
// environment variable to limit concurrency and rejoin these suites.
31+
class TestCLIRunCommand1: CLITest {
32+
func getTestName() -> String {
2633
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
2734
}
2835

29-
private func getLowercasedTestName() -> String {
36+
func getLowercasedTestName() -> String {
3037
getTestName().lowercased()
3138
}
3239

@@ -194,6 +201,16 @@ class TestCLIRunCommand: CLITest {
194201
return
195202
}
196203
}
204+
}
205+
206+
class TestCLIRunCommand2: CLITest {
207+
func getTestName() -> String {
208+
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
209+
}
210+
211+
func getLowercasedTestName() -> String {
212+
getTestName().lowercased()
213+
}
197214

198215
@Test func testRunCommandMount() throws {
199216
do {

Tests/CLITests/TestCLINoParallelCases.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ import Testing
2222
/// Tests that need total control over environment to avoid conflicts.
2323
@Suite(.serialized)
2424
class TestCLINoParallelCases: CLITest {
25-
private func getTestName() -> String {
25+
func getTestName() -> String {
2626
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
2727
}
2828

29+
func getLowercasedTestName() -> String {
30+
getTestName().lowercased()
31+
}
32+
2933
@Test func testImageSingleConcurrentDownload() throws {
3034
// removing this image during parallel tests breaks stuff!
3135
_ = try? run(arguments: ["image", "rm", alpine])
36+
defer { _ = try? run(arguments: ["image", "rm", "--all"]) }
3237
do {
3338
try doPull(imageName: alpine, args: ["--max-concurrent-downloads", "1"])
3439
let imagePresent = try isImagePresent(targetImage: alpine)
@@ -42,6 +47,7 @@ class TestCLINoParallelCases: CLITest {
4247
@Test func testImageManyConcurrentDownloads() throws {
4348
// removing this image during parallel tests breaks stuff!
4449
_ = try? run(arguments: ["image", "rm", alpine])
50+
defer { _ = try? run(arguments: ["image", "rm", "--all"]) }
4551
do {
4652
try doPull(imageName: alpine, args: ["--max-concurrent-downloads", "64"])
4753
let imagePresent = try isImagePresent(targetImage: alpine)
@@ -54,6 +60,7 @@ class TestCLINoParallelCases: CLITest {
5460

5561
@Test func testImagePruneNoImages() throws {
5662
// Prune with no images should succeed
63+
_ = try? run(arguments: ["image", "rm", "--all"])
5764
let (_, output, error, status) = try run(arguments: ["image", "prune"])
5865
if status != 0 {
5966
throw CLIError.executionFailed("image prune failed: \(error)")
@@ -64,6 +71,8 @@ class TestCLINoParallelCases: CLITest {
6471

6572
@Test func testImagePruneUnusedImages() throws {
6673
// 1. Pull the images
74+
_ = try? run(arguments: ["image", "rm", "--all"])
75+
defer { _ = try? run(arguments: ["image", "rm", "--all"]) }
6776
try doPull(imageName: alpine)
6877
try doPull(imageName: busybox)
6978

@@ -93,6 +102,10 @@ class TestCLINoParallelCases: CLITest {
93102
let containerName = "\(name)_container"
94103

95104
// 1. Pull the images
105+
_ = try? run(arguments: ["image", "rm", "--all"])
106+
defer { _ = try? run(arguments: ["image", "rm", "--all"]) }
107+
_ = try? run(arguments: ["rm", "--all", "--force"])
108+
defer { _ = try? run(arguments: ["rm", "--all", "--force"]) }
96109
try doPull(imageName: alpine)
97110
try doPull(imageName: busybox)
98111

0 commit comments

Comments
 (0)