Conversation
observed several failures due to ``` java.net.BindException: Address already in use at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:459) at java.base/sun.nio.ch.Net.bind(Net.java:448) at java.base/sun.nio.ch.AsynchronousServerSocketChannelImpl.bind(AsynchronousServerSocketChannelImpl.java:164) at org.apache.sshd.common.io.nio2.Nio2Acceptor.bind(Nio2Acceptor.java:83) at org.apache.sshd.common.io.nio2.Nio2Acceptor.bind(Nio2Acceptor.java:173) at org.apache.sshd.server.SshServer.start(SshServer.java:331) at com.cloudbees.jenkins.plugins.sshagent.SSHAgentBase.startMockSSHServer(SSHAgentBase.java:171) ``` rather than obtain a port ant t1 and then use it later at t2 just get the SSH server to use a port and then find out which port is actually being used.
| @Rule | ||
| public TemporaryFolder temp = new TemporaryFolder(); |
There was a problem hiding this comment.
the same file was being used, which if using mutliple tests in parallel could lead to some funky timing issues also.
There was a problem hiding this comment.
Will JUnit actually apply this rule since it isn't a test suite?
There was a problem hiding this comment.
its a base class of the other tests so it should. the test pass :)
There was a problem hiding this comment.
Meaning will the temp files created with it actually be cleaned up?
There was a problem hiding this comment.
yup!
Note that it was not cleaned up prior to this - one would always dangle.
| File hostKey = temp.newFile(); | ||
| sshd = SshServer.setUpDefaultServer(); | ||
| sshd.setPort(getValidPort()); | ||
| sshd.setPort(0); |
There was a problem hiding this comment.
get the SSH server to start on a random port - so that it is guaranteed to be available.
| * | ||
| * @return int with a valid port number | ||
| */ | ||
| private int getValidPort() throws IOException { |
There was a problem hiding this comment.
the port may be free immediately after it was obtained - but may have been used by something else before it was used by the SSH server.
| */ | ||
| public int getAssignedPort() { | ||
| return assignedPort; | ||
| return sshd.getPort(); |
There was a problem hiding this comment.
ask the ssh server for its port - it knows what it is!
|
|
||
| protected void startMockSSHServer() throws Exception { | ||
| File hostKey = new File(System.getProperty("java.io.tmpdir") + "/key.ser"); | ||
| hostKey.delete(); // do not carry from test to test |
There was a problem hiding this comment.
because this was using the same file accross tests and deleting it if it existed!
(running multiple tests in parallel!)
observed several failures due to
rather than obtain a port ant t1 and then use it later at t2 just get the SSH server to use a port and then find out which port is actually being used.