From dfcba59b6a77d9a730ed8d6b6728d8812ece424b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 23 Jul 2019 23:51:24 -0700 Subject: 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. --- src/channel.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') 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)) } } -- cgit v1.2.3