File tree Expand file tree Collapse file tree
src/test/kotlin/com/atlassian/performance/tools/ssh/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com.atlassian.performance.tools.ssh.api
22
3+ import org.hamcrest.CoreMatchers.containsString
34import org.junit.Assert
45import org.junit.Test
56import 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 }
You can’t perform that action at this time.
0 commit comments