From e79bb92c4b3c1573d90fffe0f7f168bbb84580fd Mon Sep 17 00:00:00 2001 From: Przemyslaw Czuj Date: Wed, 22 Jun 2022 18:07:53 +0200 Subject: [PATCH] JPERF-811: Fix flaky shouldTolerateEarlyFinish test by waiting until OS actually starts (and finishes) the process before interrupting it --- .../com/atlassian/performance/tools/ssh/api/SshTest.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt b/src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt index c035ed9..a9c68f6 100644 --- a/src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt +++ b/src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt @@ -56,7 +56,8 @@ class SshTest { SshContainer().useSsh { sshHost -> installPing(sshHost) - val fail = sshHost.runInBackground("nonexistent-command") + 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) @@ -66,4 +67,11 @@ class SshTest { 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) + } }