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..e7416e7 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 @@ -1,5 +1,6 @@ package com.atlassian.performance.tools.ssh.api +import org.hamcrest.CoreMatchers.containsString import org.junit.Assert import org.junit.Test import java.time.Duration @@ -63,6 +64,29 @@ class SshTest { } } + @Test + fun shouldTimeOutWhenStopping() { + val uninterruptibleSleep = """ + trap 'echo "got interrupted"' INT + for i in {1..10} + do + echo "sleeping... `date`" + sleep 1 + done + """.trimIndent() + SshContainer().useSsh { sshHost -> + val backgroundSleep = sshHost.runInBackground(uninterruptibleSleep) + Thread.sleep(Duration.ofSeconds(3).toMillis()) + try { + backgroundSleep.stop(Duration.ofSeconds(2)) + Assert.fail("Expected to throw") + } catch (e: Exception) { + Assert.assertThat(e.message, containsString("sleeping")); + Assert.assertThat(e.message, containsString("^Cgot interrupted")); + } + } + } + private fun installPing(sshHost: Ssh) { sshHost.newConnection().use { it.execute("apt-get update -qq && apt-get install iputils-ping -y") } }