Skip to content

Commit a1ba4f2

Browse files
committed
JPERF-811: Fix flaky shouldTolerateEarlyFinish test by waiting until OS actually starts (and finishes) the process before interrupting it
1 parent 9e6442e commit a1ba4f2

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • src/test/kotlin/com/atlassian/performance/tools/ssh/api

src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,24 @@ class SshTest {
5656
SshContainer().useSsh { sshHost ->
5757
installPing(sshHost)
5858

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

62-
Assert.assertEquals(127, failResult.exitStatus)
64+
Assert.assertEquals(127, failResult.exitStatus)
65+
}
6366
}
6467
}
6568

6669
private fun installPing(sshHost: Ssh) {
6770
sshHost.newConnection().use { it.execute("apt-get update -qq && apt-get install iputils-ping -y") }
6871
}
72+
73+
private fun Ssh.waitForAllProcessesToFinish(
74+
processCommand: String,
75+
timeout: Duration
76+
) = this.newConnection().use {
77+
it.execute("wait `pgrep '$processCommand'`", timeout)
78+
}
6979
}

0 commit comments

Comments
 (0)