From a1ba4f2ef3a2de0684fff4a0f9605cb629d4f7f0 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 --- .../performance/tools/ssh/api/SshTest.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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..e45a2a0 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,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) + } }