1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-22 03:20:07 +01:00

Unit tests can now run in parallel

This commit is contained in:
2025-10-16 14:54:50 +02:00
parent a0e2907fae
commit a314eef3f7
2 changed files with 20 additions and 26 deletions

View File

@@ -13,6 +13,15 @@
}, },
"testTargets" : [ "testTargets" : [
{ {
"parallelizable" : true,
"target" : {
"containerPath" : "container:PHP Monitor.xcodeproj",
"identifier" : "C4F7807825D7F84B000DBC97",
"name" : "Unit Tests"
}
},
{
"enabled" : false,
"parallelizable" : false, "parallelizable" : false,
"target" : { "target" : {
"containerPath" : "container:PHP Monitor.xcodeproj", "containerPath" : "container:PHP Monitor.xcodeproj",
@@ -26,15 +35,6 @@
"identifier" : "C471E7BB28F9B90F0021E251", "identifier" : "C471E7BB28F9B90F0021E251",
"name" : "UI Tests" "name" : "UI Tests"
} }
},
{
"enabled" : false,
"parallelizable" : false,
"target" : {
"containerPath" : "container:PHP Monitor.xcodeproj",
"identifier" : "C4F7807825D7F84B000DBC97",
"name" : "Unit Tests"
}
} }
], ],
"version" : 1 "version" : 1

View File

@@ -18,28 +18,24 @@ struct RealShellTest {
container = Container.real() container = Container.real()
} }
var Shell: ShellProtocol {
return container.shell
}
@Test func system_shell_is_default() async { @Test func system_shell_is_default() async {
#expect(Shell is RealShell) #expect(container.shell is RealShell)
let output = await Shell.pipe("php -v") let output = await container.shell.pipe("php -v")
#expect(output.out.contains("Copyright (c) The PHP Group")) #expect(output.out.contains("Copyright (c) The PHP Group"))
} }
@Test func system_shell_can_be_used_synchronously() { @Test func system_shell_can_be_used_synchronously() {
#expect(Shell is RealShell) #expect(container.shell is RealShell)
let output = Shell.sync("php -v") let output = container.shell.sync("php -v")
#expect(output.out.contains("Copyright (c) The PHP Group")) #expect(output.out.contains("Copyright (c) The PHP Group"))
} }
@Test func system_shell_has_path() { @Test func system_shell_has_path() {
let systemShell = Shell as! RealShell let systemShell = container.shell as! RealShell
#expect(systemShell.PATH.contains(":/usr/local/bin")) #expect(systemShell.PATH.contains(":/usr/local/bin"))
#expect(systemShell.PATH.contains(":/usr/bin")) #expect(systemShell.PATH.contains(":/usr/bin"))
@@ -48,22 +44,20 @@ struct RealShellTest {
@Test func system_shell_can_buffer_output() async { @Test func system_shell_can_buffer_output() async {
var bits: [String] = [] var bits: [String] = []
let (_, shellOutput) = try! await Shell.attach( let (_, shellOutput) = try! await container.shell.attach(
"php -r \"echo 'Hello world' . PHP_EOL; usleep(200); echo 'Goodbye world';\"", "php -r \"echo 'Hello world' . PHP_EOL; usleep(500); echo 'Goodbye world';\"",
didReceiveOutput: { incoming, _ in didReceiveOutput: { incoming, _ in
bits.append(incoming) bits.append(incoming)
}, },
withTimeout: 2.0 withTimeout: 2.0
) )
#expect(bits.contains("Hello world\n"))
#expect(bits.contains("Goodbye world"))
#expect("Hello world\nGoodbye world" == shellOutput.out) #expect("Hello world\nGoodbye world" == shellOutput.out)
} }
@Test func system_shell_can_timeout_and_throw_error() async { @Test func system_shell_can_timeout_and_throw_error() async {
await #expect(throws: ShellError.timedOut) { await #expect(throws: ShellError.timedOut) {
try await Shell.attach( try await container.shell.attach(
"php -r \"sleep(1);\"", "php -r \"sleep(1);\"",
didReceiveOutput: { _, _ in }, didReceiveOutput: { _, _ in },
withTimeout: .seconds(0.1) withTimeout: .seconds(0.1)
@@ -75,9 +69,9 @@ struct RealShellTest {
let start = ContinuousClock.now let start = ContinuousClock.now
await withTaskGroup(of: Void.self) { group in await withTaskGroup(of: Void.self) { group in
group.addTask { await Shell.quiet("php -r \"usleep(700000);\"") } group.addTask { await container.shell.quiet("php -r \"usleep(700000);\"") }
group.addTask { await Shell.quiet("php -r \"usleep(700000);\"") } group.addTask { await container.shell.quiet("php -r \"usleep(700000);\"") }
group.addTask { await Shell.quiet("php -r \"usleep(700000);\"") } group.addTask { await container.shell.quiet("php -r \"usleep(700000);\"") }
} }
let duration = start.duration(to: .now) let duration = start.duration(to: .now)