mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-27 03:06:24 -05:00
fix(tests): Electrum balancer unit test (#399)
This commit is contained in:
parent
742acca444
commit
c12742c77b
1 changed files with 14 additions and 6 deletions
|
|
@ -949,7 +949,14 @@ mod tests {
|
||||||
factory.add_client(MockElectrumClient::new(urls[1].clone()));
|
factory.add_client(MockElectrumClient::new(urls[1].clone()));
|
||||||
factory.add_client(MockElectrumClient::new(urls[2].clone()));
|
factory.add_client(MockElectrumClient::new(urls[2].clone()));
|
||||||
|
|
||||||
let balancer = ElectrumBalancer::new_with_factory(urls, factory.clone())
|
// Use config with min_retries = 0 to test basic switching behavior
|
||||||
|
// This ensures total_attempts = max(0, 3) = 3, but behavior is cleaner
|
||||||
|
let config = ElectrumBalancerConfig {
|
||||||
|
request_timeout: 5,
|
||||||
|
min_retries: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let balancer = ElectrumBalancer::new_with_config_and_factory(urls, config, factory.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
@ -961,7 +968,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
assert!(result1.is_ok());
|
assert!(result1.is_ok());
|
||||||
|
|
||||||
// Second call should stick with client 1 since it works
|
// Second call should also try client 0 first (fails), then client 1 (succeeds)
|
||||||
let result2 = balancer
|
let result2 = balancer
|
||||||
.call("test", |client| {
|
.call("test", |client| {
|
||||||
client.transaction_broadcast(&create_dummy_transaction())
|
client.transaction_broadcast(&create_dummy_transaction())
|
||||||
|
|
@ -969,10 +976,11 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
assert!(result2.is_ok());
|
assert!(result2.is_ok());
|
||||||
|
|
||||||
// Verify call counts: client 0 called once (failed), client 1 called twice (succeeded both times)
|
// Verify call counts:
|
||||||
assert_eq!(factory.get_client(0).unwrap().call_count(), 1);
|
// Both calls try client 0 first (fails both times), then client 1 (succeeds both times)
|
||||||
assert_eq!(factory.get_client(1).unwrap().call_count(), 2);
|
assert_eq!(factory.get_client(0).unwrap().call_count(), 2); // Called on both attempts
|
||||||
assert_eq!(factory.get_client(2).unwrap().call_count(), 0);
|
assert_eq!(factory.get_client(1).unwrap().call_count(), 2); // Called on both attempts after client 0 fails
|
||||||
|
assert_eq!(factory.get_client(2).unwrap().call_count(), 0); // Never called
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue