Improved test stability

This commit is contained in:
Jeroen van Erp
2017-08-24 13:59:58 +02:00
parent aa7748395d
commit 0918bc626f
2 changed files with 15 additions and 0 deletions

View File

@@ -137,6 +137,15 @@ public class LocalPortForwarder {
listen(Thread.currentThread());
}
/**
* Returns whether this listener is running (ie. whether a thread is attached to it).
*
* @return
*/
public boolean isRunning() {
return this.runningThread != null && !serverSocket.isClosed();
}
/**
* Start listening for incoming connections and forward to remote host as a channel and ensure that the thread is registered.
* This is useful if for instance {@link #close() is called from another thread}

View File

@@ -19,6 +19,9 @@ import com.hierynomus.sshj.test.SshFixture
import net.schmizz.sshj.connection.channel.direct.LocalPortForwarder
import org.junit.Rule
import spock.lang.Specification
import spock.util.concurrent.PollingConditions
import java.util.concurrent.CountDownLatch
class LocalPortForwarderSpec extends Specification {
@Rule
@@ -44,6 +47,9 @@ class LocalPortForwarderSpec extends Specification {
thread.start()
then:
new PollingConditions().eventually {
lpf.isRunning()
}
thread.isAlive()
when: