Skip to content

Commit

Permalink
JPERF-811: Fix flaky shouldTolerateEarlyFinish test by waiting until …
Browse files Browse the repository at this point in the history
…OS actually starts (and finishes) the process before interrupting it
  • Loading branch information
pczuj committed Jun 22, 2022
1 parent 9e6442e commit a1ba4f2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ class SshTest {
SshContainer().useSsh { sshHost ->
installPing(sshHost)

val fail = sshHost.runInBackground("nonexistent-command")
val failResult = fail.stop(Duration.ofMillis(20))
repeat(1000) {
val fail = sshHost.runInBackground("nonexistant-command")
sshHost.waitForAllProcessesToFinish("nonexistant-command", Duration.ofMillis(100))
val failResult = fail.stop(Duration.ofMillis(20))

Assert.assertEquals(127, failResult.exitStatus)
Assert.assertEquals(127, failResult.exitStatus)
}
}
}

private fun installPing(sshHost: Ssh) {
sshHost.newConnection().use { it.execute("apt-get update -qq && apt-get install iputils-ping -y") }
}

private fun Ssh.waitForAllProcessesToFinish(
processCommand: String,
timeout: Duration
) = this.newConnection().use {
it.execute("wait `pgrep '$processCommand'`", timeout)
}
}

0 comments on commit a1ba4f2

Please sign in to comment.