Skip to content

Commit

Permalink
Test background stop timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed May 14, 2021
1 parent a4dd99c commit 4aeeb76
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/test/kotlin/com/atlassian/performance/tools/ssh/api/SshTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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") }
}
Expand Down

0 comments on commit 4aeeb76

Please sign in to comment.