Skip to content

Commit e322998

Browse files
committed
test: fix nextest flaky test
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 32f30db commit e322998

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

crates/tap-agent/tests/sender_account_manager_test.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use indexer_tap_agent::{
1313
create_received_receipt, create_sender_accounts_manager, store_receipt, ALLOCATION_ID_0,
1414
},
1515
};
16-
use ractor::ActorRef;
16+
use ractor::{ActorRef, ActorStatus};
1717
use serde_json::json;
1818
use sqlx::PgPool;
19-
use test_assets::{flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
19+
use test_assets::{assert_while_retry, flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
2020
use wiremock::{
2121
matchers::{body_string_contains, method},
2222
Mock, MockServer, ResponseTemplate,
@@ -74,17 +74,17 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
7474
flush_messages(&notify).await;
7575

7676
// verify if create sender account
77-
let actor_ref =
77+
let sender_account_ref =
7878
ActorRef::<SenderAccountMessage>::where_is(format!("{}:{}", prefix.clone(), SENDER.1));
79-
assert!(actor_ref.is_some());
79+
assert!(sender_account_ref.is_some());
8080

8181
let receipt = create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, 1, 1, TRIGGER_VALUE - 10);
8282
store_receipt(&pgpool, receipt.signed_receipt())
8383
.await
8484
.unwrap();
8585

8686
// we expect it to create a sender allocation
87-
actor_ref
87+
sender_account_ref
8888
.clone()
8989
.unwrap()
9090
.cast(SenderAccountMessage::UpdateAllocationIds(
@@ -93,15 +93,28 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
9393
.collect(),
9494
))
9595
.unwrap();
96-
flush_messages(&notify).await;
96+
97+
assert_while_retry!({
98+
ActorRef::<SenderAllocationMessage>::where_is(format!(
99+
"{}:{}:{}",
100+
prefix, SENDER.1, ALLOCATION_ID_0,
101+
))
102+
.is_none()
103+
});
104+
let allocation_ref = ActorRef::<SenderAllocationMessage>::where_is(format!(
105+
"{}:{}:{}",
106+
prefix, SENDER.1, ALLOCATION_ID_0,
107+
))
108+
.unwrap();
97109

98110
// try to delete sender allocation_id
99-
actor_ref
111+
sender_account_ref
100112
.clone()
101113
.unwrap()
102114
.cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new()))
103115
.unwrap();
104-
flush_messages(&notify).await;
116+
allocation_ref.wait(None).await.unwrap();
117+
assert_eq!(allocation_ref.get_status(), ActorStatus::Stopped);
105118

106119
assert!(ActorRef::<SenderAllocationMessage>::where_is(format!(
107120
"{}:{}:{}",
@@ -116,15 +129,14 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
116129
))
117130
.unwrap();
118131

119-
flush_messages(&notify).await;
132+
sender_account_ref.unwrap().wait(None).await.unwrap();
120133
// verify if it gets removed
121134
let actor_ref = ActorRef::<SenderAccountMessage>::where_is(format!("{}:{}", prefix, SENDER.1));
122135
assert!(actor_ref.is_none());
123136

124-
//verify the rav is marked as last
125137
let rav_marked_as_last = sqlx::query!(
126138
r#"
127-
SELECT * FROM scalar_tap_ravs WHERE last = true;
139+
SELECT * FROM scalar_tap_ravs WHERE last;
128140
"#,
129141
)
130142
.fetch_all(&pgpool)

0 commit comments

Comments
 (0)