summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWez Furlong <wez@wezfurlong.org>2019-07-23 23:51:24 -0700
committerWez Furlong <wez@wezfurlong.org>2019-07-29 08:55:06 -0700
commitdfcba59b6a77d9a730ed8d6b6728d8812ece424b (patch)
treea60942b1ef1d25a947c871b42d1509ab7bbd7da2 /src
parent9efb2d664971682278b37eb40152c27f6e231645 (diff)
downloadssh2-rs-dfcba59b6a77d9a730ed8d6b6728d8812ece424b.zip
Make channel tests more robust to stderr output
At the start of feb 2019 the tests started to fail on macos on Travis. No changes were made to the repo, so the problem must be environmental. It turns out that the server was emitting stderr output, and since the tests were not consuming stderr, this made `channel.eof()` always return false. The resolution is to drain both stdout and stderr in the tests before making assertions with `channel.eof()`. I've also updated the doc comment on `channel.eof()` to reflect this, as it is a bit of a sharp edge.
Diffstat (limited to 'src')
-rw-r--r--src/channel.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/channel.rs b/src/channel.rs
index 03bbba0..7086f5d 100644
--- a/src/channel.rs
+++ b/src/channel.rs
@@ -328,7 +328,10 @@ impl Channel {
self.read_limit = Some(limit);
}
- /// Check if the remote host has sent an EOF status for the selected stream.
+ /// Check if the remote host has sent an EOF status for the channel.
+ /// Take care: the EOF status is for the entire channel which can be confusing
+ /// because the reading from the channel reads only the stdout stream.
+ /// unread, buffered, stderr data will cause eof() to return false.
pub fn eof(&self) -> bool {
self.read_limit == Some(0) || unsafe { raw::libssh2_channel_eof(self.raw) != 0 }
}
@@ -342,6 +345,10 @@ impl Channel {
}
/// Wait for the remote end to send EOF.
+ /// Note that unread buffered stdout and stderr will cause this function
+ /// to return `Ok(())` without waiting.
+ /// You should call the eof() function after calling this to check the
+ /// status of the channel.
pub fn wait_eof(&mut self) -> Result<(), Error> {
unsafe { self.sess.rc(raw::libssh2_channel_wait_eof(self.raw)) }
}