Skip to content

Commit

Permalink
handle close() result
Browse files Browse the repository at this point in the history
  • Loading branch information
fereidani committed May 31, 2023
1 parent efb8713 commit 0d3a3e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions tests/async_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod asyncs {
});
list.push(c);
}
r.close();
r.close().unwrap();
for c in list {
c.await.unwrap();
}
Expand All @@ -255,15 +255,15 @@ mod asyncs {
#[tokio::test]
async fn recv_from_closed_channel() {
let (tx, rx) = new::<u64>(Some(1));
tx.close();
tx.close().unwrap();
assert_eq!(rx.recv().await.err().unwrap(), ReceiveError::Closed);
}

#[tokio::test]
async fn recv_from_closed_channel_queue() {
let (tx, rx) = new(Some(1));
tx.send(Box::new(1)).await.unwrap();
tx.close();
tx.close().unwrap();
// it's not possible to read data from queue of fully closed channel
assert_eq!(rx.recv().await.err().unwrap(), ReceiveError::Closed);
}
Expand All @@ -281,7 +281,7 @@ mod asyncs {
#[tokio::test]
async fn send_to_closed_channel() {
let (tx, rx) = new(Some(1));
rx.close();
rx.close().unwrap();
assert_eq!(tx.send(Box::new(1)).await.err().unwrap(), SendError::Closed);
}

Expand All @@ -304,7 +304,7 @@ mod asyncs {
for c in list {
c.abort();
}
r.close();
r.close().unwrap();
}

// Drop tests
Expand All @@ -329,7 +329,7 @@ mod asyncs {
}
tokio::time::sleep(Duration::from_millis(500)).await;
assert_eq!(counter.load(Ordering::SeqCst), 10_usize);
r.close();
r.close().unwrap();
}

#[tokio::test]
Expand All @@ -349,7 +349,7 @@ mod asyncs {
for c in list {
c.await.unwrap();
}
r.close();
r.close().unwrap();
assert_eq!(counter.load(Ordering::SeqCst), 10_usize);
}

Expand All @@ -362,14 +362,14 @@ mod asyncs {
let counter = counter.clone();
drop(s.send(DropTester::new(counter, 1234)));
}
r.close();
r.close().unwrap();
assert_eq!(counter.load(Ordering::SeqCst), 10_usize);
}

#[tokio::test]
async fn drop_test_send_to_closed() {
let (s, r) = new(Some(10));
r.close();
r.close().unwrap();
let counter = Arc::new(AtomicUsize::new(0));
for _ in 0..10 {
let counter = counter.clone();
Expand Down
12 changes: 6 additions & 6 deletions tests/sync_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ fn recv_from_half_closed_channel() {
#[test]
fn recv_from_closed_channel() {
let (tx, rx) = new::<u64>(Some(1));
tx.close();
tx.close().unwrap();
assert_eq!(rx.recv().err().unwrap(), ReceiveError::Closed);
}

#[test]
fn recv_from_closed_channel_queue() {
let (tx, rx) = new(Some(1));
tx.send(Box::new(1)).unwrap();
tx.close();
tx.close().unwrap();
// it's not possible to read data from queue of fully closed channel
assert_eq!(rx.recv().err().unwrap(), ReceiveError::Closed);
}
Expand All @@ -297,7 +297,7 @@ fn send_to_half_closed_channel() {
#[test]
fn send_to_closed_channel() {
let (tx, rx) = new(Some(1));
rx.close();
rx.close().unwrap();
assert_eq!(tx.send(Box::new(1)).err().unwrap(), SendError::Closed);
}

Expand All @@ -316,15 +316,15 @@ fn drop_test_in_queue() {
for _ in 0..10 {
s.send(DropTester::new(counter.clone(), 1234)).unwrap();
}
r.close();
r.close().unwrap();
assert_eq!(counter.load(Ordering::SeqCst), 10_usize);
}

#[test]
fn drop_test_send_to_closed() {
let counter = Arc::new(AtomicUsize::new(0));
let (s, r) = new(Some(10));
r.close();
r.close().unwrap();
for _ in 0..10 {
// will fail
let _ = s.send(DropTester::new(counter.clone(), 1234));
Expand Down Expand Up @@ -360,7 +360,7 @@ fn drop_test_in_signal() {
list.push(t);
}
std::thread::sleep(Duration::from_millis(1000));
r.close();
r.close().unwrap();
for t in list {
t.join().unwrap();
}
Expand Down

0 comments on commit 0d3a3e1

Please sign in to comment.