File size: 1,090 Bytes
ea39c0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
use tokio::sync::oneshot;

use super::AcceptedConnectionSource;
use crate::ExecServerClientConnectOptions;

#[tokio::test]
async fn replacement_claim_is_released_when_handoff_is_cancelled() {
    let source = AcceptedConnectionSource::new(ExecServerClientConnectOptions::default());
    let (claimed_tx, claimed_rx) = oneshot::channel();
    let (_release_tx, release_rx) = oneshot::channel::<()>();

    let handoff = tokio::spawn({
        let source = source.clone();
        async move {
            let _submission = source
                .begin_replacement()
                .expect("the first replacement should claim the handoff");
            claimed_tx
                .send(())
                .expect("the test should wait for the claim");
            let _ = release_rx.await;
        }
    });

    claimed_rx.await.expect("the handoff should be claimed");
    assert!(source.begin_replacement().is_err());

    handoff.abort();
    let _ = handoff.await;

    source
        .begin_replacement()
        .expect("a new replacement should be accepted after cancellation");
}