Skip to content

Commit 4aeeb76

Browse files
committed
Test background stop timeout
1 parent a4dd99c commit 4aeeb76

1 file changed

Lines changed: 24 additions & 0 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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.atlassian.performance.tools.ssh.api
22

3+
import org.hamcrest.CoreMatchers.containsString
34
import org.junit.Assert
45
import org.junit.Test
56
import java.time.Duration
@@ -63,6 +64,29 @@ class SshTest {
6364
}
6465
}
6566

67+
@Test
68+
fun shouldTimeOutWhenStopping() {
69+
val uninterruptibleSleep = """
70+
trap 'echo "got interrupted"' INT
71+
for i in {1..10}
72+
do
73+
echo "sleeping... `date`"
74+
sleep 1
75+
done
76+
""".trimIndent()
77+
SshContainer().useSsh { sshHost ->
78+
val backgroundSleep = sshHost.runInBackground(uninterruptibleSleep)
79+
Thread.sleep(Duration.ofSeconds(3).toMillis())
80+
try {
81+
backgroundSleep.stop(Duration.ofSeconds(2))
82+
Assert.fail("Expected to throw")
83+
} catch (e: Exception) {
84+
Assert.assertThat(e.message, containsString("sleeping"));
85+
Assert.assertThat(e.message, containsString("^Cgot interrupted"));
86+
}
87+
}
88+
}
89+
6690
private fun installPing(sshHost: Ssh) {
6791
sshHost.newConnection().use { it.execute("apt-get update -qq && apt-get install iputils-ping -y") }
6892
}

0 commit comments

Comments
 (0)