1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

👌 Add delay global function

This commit is contained in:
2022-10-08 00:27:29 +02:00
parent 6db5cdec25
commit f5d2ec2b7e
3 changed files with 11 additions and 6 deletions

View File

@ -49,3 +49,11 @@ func grepContains(file: String, query: String) async -> Bool {
.trimmingCharacters(in: .whitespacesAndNewlines)
.contains("YES")
}
/**
Attempts to introduce sleep for a particular duration. Use with caution.
Only intended for testing purposes.
*/
func delay(seconds: Double) async {
try! await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
}

View File

@ -92,8 +92,7 @@ class SystemShell: Shellable {
// (in order to debug or identify async issues)
if ProcessInfo.processInfo.environment["SLOW_SHELL_MODE"] != nil {
print("[SLOW SHELL] \(command)")
let delayInSeconds = 3
try! await Task.sleep(nanoseconds: UInt64(delayInSeconds * 1_000_000_000))
await delay(seconds: 3.0)
}
task.standardOutput = outputPipe

View File

@ -37,8 +37,7 @@ public class TestableShell: Shellable {
// Seriously slow down the shell's return rate in order to debug or identify async issues
if ProcessInfo.processInfo.environment["SLOW_SHELL_MODE"] != nil {
print("[SLOW SHELL] \(command)")
let delayInSeconds = 3
try! await Task.sleep(nanoseconds: UInt64(delayInSeconds * 1_000_000_000))
await delay(seconds: 3.0)
}
// This assertion will only fire during test builds
@ -100,8 +99,7 @@ struct BatchFakeShellOutput {
for item in items {
if !ignoreDelay {
let delay = UInt64(item.delay * 1_000_000_000)
try! await Task.sleep(nanoseconds: delay)
await delay(seconds: item.delay)
}
if item.stream == .stdErr {