Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test background stop timeout #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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