Skip to content

Commit e438c8a

Browse files
committed
tests: Add check for correct error reporting from try_recv()
1 parent 23687a7 commit e438c8a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/platform/test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,23 @@ fn try_recv() {
744744
assert!(rx.try_recv().is_err());
745745
}
746746

747+
/// Checks that a channel closed notification is returned by `try_recv()`.
748+
///
749+
/// Also checks that the "no data" notification returned by `try_recv()`
750+
/// when no data is pending but before the channel is closed,
751+
/// is distinguishable from the actual "channel closed" notification.
752+
#[test]
753+
fn no_senders_notification_try_recv() {
754+
let (sender, receiver) = platform::channel().unwrap();
755+
let result = receiver.try_recv();
756+
assert!(result.is_err());
757+
assert!(!result.unwrap_err().channel_is_closed());
758+
drop(sender);
759+
let result = receiver.try_recv();
760+
assert!(result.is_err());
761+
assert!(result.unwrap_err().channel_is_closed());
762+
}
763+
747764
#[test]
748765
fn try_recv_large() {
749766
let (tx, rx) = platform::channel().unwrap();

0 commit comments

Comments
 (0)