aboutsummaryrefslogtreecommitdiff
path: root/vendor/flume/tests/check_same_channel.rs
blob: edb82c3839818fa4fa9de794806c9170eab2ff7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[test]
fn same_sender() {
    let (tx1, _rx) = flume::unbounded::<()>();
    let tx2 = tx1.clone();

    assert!(tx1.same_channel(&tx2));

    let (tx3, _rx) = flume::unbounded::<()>();

    assert!(!tx1.same_channel(&tx3));
    assert!(!tx2.same_channel(&tx3));
}

#[test]
fn same_receiver() {
    let (_tx, rx1) = flume::unbounded::<()>();
    let rx2 = rx1.clone();

    assert!(rx1.same_channel(&rx2));

    let (_tx, rx3) = flume::unbounded::<()>();

    assert!(!rx1.same_channel(&rx3));
    assert!(!rx2.same_channel(&rx3));
}

#[cfg(feature = "async")]
#[test]
fn same_send_sink() {
    let (tx1, _rx) = flume::unbounded::<()>();
    let tx1 = tx1.into_sink();
    let tx2 = tx1.clone();

    assert!(tx1.same_channel(&tx2));

    let (tx3, _rx) = flume::unbounded::<()>();
    let tx3 = tx3.into_sink();

    assert!(!tx1.same_channel(&tx3));
    assert!(!tx2.same_channel(&tx3));
}

#[cfg(feature = "async")]
#[test]
fn same_recv_stream() {
    let (_tx, rx1) = flume::unbounded::<()>();
    let rx1 = rx1.into_stream();
    let rx2 = rx1.clone();

    assert!(rx1.same_channel(&rx2));

    let (_tx, rx3) = flume::unbounded::<()>();
    let rx3 = rx3.into_stream();

    assert!(!rx1.same_channel(&rx3));
    assert!(!rx2.same_channel(&rx3));
}