From 4aeeb761f1dfe8279949cf52088efabd43ecba8d Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Fri, 14 May 2021 15:52:46 +0200 Subject: [PATCH] Test background stop timeout --- .../performance/tools/ssh/api/SshTest.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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") } }