Files
container/Tests/IntegrationTests/Build/TestCLIBuilderLifecycleSerial.swift
T
J Logan d1d763530d Fix BuilderStart race, parallelize container build tests. (#2002)
- Closes #2001.
- Handle "container exists" error gracefully instead
  of failing, when trying to start the buildkit container.
- Move build tests to parallel suites, while the builder
  lifecycle tests remain serial. Parallel builds don't
  use the fixture lock that deletes and restarts the
  builder and runs a build block in isolation.
2026-07-23 15:50:59 -07:00

71 lines
3.0 KiB
Swift

//===----------------------------------------------------------------------===//
// Copyright © 2026 Apple Inc. and the container project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
import ContainerTestSupport
import Darwin
import Foundation
import Testing
/// Tests for `container builder start`, `stop`, and `delete` lifecycle commands.
///
/// Serialized because they stop/delete the shared `buildkit` container, which
/// would race with in-flight builds in the concurrent pool.
@Suite(.serialized)
struct TestCLIBuilderLifecycleSerial {
@Test func testBuilderStartStopCommand() async throws {
try await ContainerFixture.with { f in
f.addCleanup { try? f.builderDelete(force: true) }
try f.builderStart()
try await f.waitForBuilderRunning()
let status1 = try f.getContainerStatus("buildkit")
#expect(status1 == "running", "buildkit container should be running")
try f.builderStop()
let status2 = try f.getContainerStatus("buildkit")
#expect(status2 == "stopped", "buildkit container should be stopped")
}
}
@Test func testBuilderEnvironmentColors() async throws {
try await ContainerFixture.with { f in
let originalColors = ProcessInfo.processInfo.environment["BUILDKIT_COLORS"]
let originalNoColor = ProcessInfo.processInfo.environment["NO_COLOR"]
f.addCleanup {
if let c = originalColors { setenv("BUILDKIT_COLORS", c, 1) } else { unsetenv("BUILDKIT_COLORS") }
if let n = originalNoColor { setenv("NO_COLOR", n, 1) } else { unsetenv("NO_COLOR") }
_ = try? f.builderDelete(force: true)
}
_ = try? f.builderDelete(force: true)
setenv("BUILDKIT_COLORS", "run=green:warning=yellow:error=red:cancel=cyan", 1)
setenv("NO_COLOR", "true", 1)
try f.run(["builder", "start"]).check()
try await f.waitForBuilderRunning()
let container = try f.inspectContainer("buildkit")
let env = container.configuration.initProcess.environment
#expect(
env.contains("BUILDKIT_COLORS=run=green:warning=yellow:error=red:cancel=cyan"),
"BUILDKIT_COLORS should be forwarded to the buildkit container")
#expect(
env.contains("NO_COLOR=true"),
"NO_COLOR should be forwarded to the buildkit container")
}
}
}