Skip to content

Commit 07fd3c9

Browse files
committed
fixup! 2beccfa
1 parent fccecc8 commit 07fd3c9

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

simln-lib/src/lib.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ mod tests {
16211621
use std::time::Duration;
16221622
use tokio::sync::Mutex;
16231623
use tokio_util::task::TaskTracker;
1624+
use std::sync::Mutex as StdMutex;
16241625

16251626
#[test]
16261627
fn create_seeded_mut_rng() {
@@ -1947,6 +1948,8 @@ mod tests {
19471948
let node_1 = &nodes[0];
19481949
let mut mock_node_1 = MockLightningNode::new();
19491950

1951+
let payments_list = Arc::new(StdMutex::new(Vec::new()));
1952+
19501953
// Set up node 1 expectations
19511954
let node_1_clone = node_1.clone();
19521955
mock_node_1
@@ -1967,9 +1970,13 @@ mod tests {
19671970
payment_outcome: crate::PaymentOutcome::Success,
19681971
})
19691972
});
1973+
let pl1 = payments_list.clone();
19701974
mock_node_1
19711975
.expect_send_payment()
1972-
.returning(|_, _| Ok(lightning::ln::PaymentHash([0; 32])));
1976+
.returning(move |a, _| {
1977+
pl1.lock().unwrap().push(a);
1978+
Ok(lightning::ln::PaymentHash([0; 32]))
1979+
});
19731980

19741981
clients.insert(node_1.pubkey, Arc::new(Mutex::new(mock_node_1)));
19751982

@@ -1999,7 +2006,7 @@ mod tests {
19992006
});
20002007
mock_node_2
20012008
.expect_send_payment()
2002-
.returning(|_, _| Ok(lightning::ln::PaymentHash([1; 32])));
2009+
.returning(move |_, _| { Ok(lightning::ln::PaymentHash([1; 32])) });
20032010

20042011
clients.insert(node_2.pubkey, Arc::new(Mutex::new(mock_node_2)));
20052012

@@ -2027,9 +2034,15 @@ mod tests {
20272034
payment_outcome: crate::PaymentOutcome::Success,
20282035
})
20292036
});
2037+
let pl3 = payments_list.clone();
20302038
mock_node_3
20312039
.expect_send_payment()
2032-
.returning(|_, _| Ok(lightning::ln::PaymentHash([2; 32])));
2040+
.returning(move |a, _|
2041+
{
2042+
pl3.lock().unwrap().push(a);
2043+
Ok(lightning::ln::PaymentHash([2; 32]))
2044+
}
2045+
);
20332046

20342047
clients.insert(node_3.pubkey, Arc::new(Mutex::new(mock_node_3)));
20352048

@@ -2059,7 +2072,7 @@ mod tests {
20592072
});
20602073
mock_node_4
20612074
.expect_send_payment()
2062-
.returning(|_, _| Ok(lightning::ln::PaymentHash([3; 32])));
2075+
.returning(move |_, _| { Ok(lightning::ln::PaymentHash([3; 32])) });
20632076

20642077
clients.insert(node_4.pubkey, Arc::new(Mutex::new(mock_node_4)));
20652078

@@ -2069,7 +2082,7 @@ mod tests {
20692082
source: node_1.clone(),
20702083
destination: node_2.clone(),
20712084
start_secs: None,
2072-
count: Some(10), // 10 payments
2085+
count: Some(5), // 10 payments
20732086
interval_secs: crate::ValueOrRange::Value(2), // 2 second interval
20742087
amount_msat: crate::ValueOrRange::Value(2000), // 2000 msats
20752088
};
@@ -2079,7 +2092,7 @@ mod tests {
20792092
source: node_3.clone(),
20802093
destination: node_4.clone(),
20812094
start_secs: None,
2082-
count: Some(10), // 10 payments
2095+
count: Some(5), // 10 payments
20832096
interval_secs: crate::ValueOrRange::Value(4), // 4 second interval
20842097
amount_msat: crate::ValueOrRange::Value(3000), // 3000 msats
20852098
};
@@ -2106,21 +2119,18 @@ mod tests {
21062119
let start = std::time::Instant::now();
21072120
let _ = simulation.run(&vec![activity_1, activity_2]).await;
21082121
let elapsed = start.elapsed();
2122+
2123+
let expected_payment_list = vec![node_2.pubkey, node_2.pubkey, node_4.pubkey, node_2.pubkey, node_4.pubkey, node_2.pubkey, node_4.pubkey, node_2.pubkey, node_4.pubkey, node_4.pubkey];
21092124

2110-
// Check that simulation ran 60 because
2111-
// from activity_1 there are 10 payments with a wait_time of 2s -> 20s
2112-
// from activity_2 there are 10 payments with a wait_time of 4s -> 40s
2125+
// Check that simulation ran 30 because
2126+
// from activity_1 there are 5 payments with a wait_time of 2s -> 10s
2127+
// from activity_2 there are 5 payments with a wait_time of 4s -> 20s
21132128
assert!(
2114-
elapsed >= Duration::from_secs(60),
2115-
"Simulation should have run at least for 54s, took {:?}",
2129+
elapsed >= Duration::from_secs(30),
2130+
"Simulation should have run at least for 30s, took {:?}",
21162131
elapsed
21172132
);
21182133

2119-
let payments = simulation.get_total_payments().await;
2120-
2121-
// We expect 20 payments to be completed
2122-
// from activity_1 there are 10 payments
2123-
// from activity_2 there are 10 payments
2124-
assert!(payments == 20, "Expected 20 payments, got {:?}", payments);
2134+
assert!(payments_list.lock().unwrap().as_ref() == expected_payment_list, "The expected order of payments is not correct");
21252135
}
21262136
}

0 commit comments

Comments
 (0)