public void testCommandDeadlock() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
client.start();
ClientSession session = client.connect("localhost", port).await().getSession();
session.authPassword("smx", "smx").await().isSuccess();
ChannelExec channel = session.createExecChannel("test");
channel.setOut(new NoCloseOutputStream(System.out));
channel.setErr(new NoCloseOutputStream(System.err));
channel.open().await();
Thread.sleep(100);
try {
for (int i = 0; i < 100; i++) {
channel.getInvertedIn().write("a".getBytes());
channel.getInvertedIn().flush();
}
} catch (SshException e) {
// That's ok, the channel is being closed by the other side
}
assertEquals(ChannelExec.CLOSED, channel.waitFor(ChannelExec.CLOSED, 0) & ChannelExec.CLOSED);
session.close(false).await();
client.stop();
}