Restart event loop in tests

Alice was attempting to create a new event loop using the same listen addr as the old one which was still running. This commit aborts the event loop before creating a new one.
This commit is contained in:
rishflab 2021-01-22 13:33:31 +11:00 committed by Franck Royer
parent 77fc5743a2
commit 1597f5336b
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
11 changed files with 63 additions and 48 deletions

View file

@ -8,8 +8,8 @@ use testutils::bob_run_until::is_btc_locked;
#[tokio::test]
async fn alice_punishes_if_bob_never_acts_after_fund() {
testutils::setup_test(|mut ctx| async move {
let alice_swap = ctx.new_swap_as_alice().await;
let bob_swap = ctx.new_swap_as_bob().await;
let (alice_swap, _) = ctx.new_swap_as_alice().await;
let (bob_swap, bob_join_handle) = ctx.new_swap_as_bob().await;
let alice = alice::run(alice_swap);
let alice_handle = tokio::spawn(alice);
@ -23,7 +23,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
// Restart Bob after Alice punished to ensure Bob transitions to
// punished and does not run indefinitely
let bob_swap = ctx.recover_bob_from_db().await;
let bob_swap = ctx.stop_and_resume_bob_from_db(bob_join_handle).await;
assert!(matches!(bob_swap.state, BobState::BtcLocked {..}));
let bob_state = bob::run(bob_swap).await.unwrap();