Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Sources/Integration/ProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,71 @@ extension IntegrationSuite {
}
}

func testMultipleConcurrentProcessesOutput() async throws {
let id = "test-concurrent-processes-output"

let bs = try await bootstrap()
let container = LinuxContainer(
id,
rootfs: bs.rootfs,
vmm: bs.vmm
)
container.arguments = ["/bin/sleep", "1000"]

do {
try await container.create()
try await container.start()

let execConfig = ContainerizationOCI.Process(
args: ["/bin/echo", "hi"],
env: ["PATH=\(LinuxContainer.defaultPath)"]
)

try await withThrowingTaskGroup(of: Void.self) { group in
for i in 0...80 {
let idx = i
group.addTask {
let buffer = BufferWriter()

var config = execConfig
config.args[1] = "hi\(idx)"

let exec = try await container.exec(
"exec-\(idx)",
configuration: config,
stdout: buffer,
)
try await exec.start()

let status = try await exec.wait()
if status != 0 {
throw IntegrationError.assert(msg: "process status \(status) != 0")
}

let output = String(data: buffer.data, encoding: .utf8)
guard output == "hi\(idx)\n" else {
throw IntegrationError.assert(
msg: "process should have returned on stdout 'hi\(idx)' != '\(output!))")
}
try await exec.delete()
}
}

// wait for all the exec'd processes.
try await group.waitForAll()
print("all group processes exit")

// kill the init process.
try await container.kill(SIGKILL)
let status = try await container.wait()
try await container.stop()
print("\(status)")
}
} catch {
throw error
}
}

func testProcessUser() async throws {
let id = "test-process-user"

Expand Down
9 changes: 5 additions & 4 deletions Sources/Integration/Suite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ struct IntegrationSuite: AsyncParsableCommand {
"process false": testProcessFalse,
"process echo hi": testProcessEchoHi,
"process user": testProcessUser,
"test multiple concurrent processes": testMultipleConcurrentProcesses,
"test container hostname": testHostname,
"test container mount": testMounts,
"test nested virt": testNestedVirtualizationEnabled,
"multiple concurrent processes": testMultipleConcurrentProcesses,
"multiple concurrent processes with output": testMultipleConcurrentProcessesOutput,
"container hostname": testHostname,
"container mount": testMounts,
"nested virt": testNestedVirtualizationEnabled,
]

var passed = 0
Expand Down