This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: concurrency insert between pending and delivered (#467)
- Loading branch information
Showing
27 changed files
with
352 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::{future::IntoFuture, sync::Arc, time::Duration}; | ||
|
||
use rstest::rstest; | ||
use tokio::{ | ||
spawn, | ||
sync::{broadcast, mpsc}, | ||
}; | ||
use topos_core::uci::Certificate; | ||
use topos_crypto::{messages::MessageSigner, validator_id::ValidatorId}; | ||
use topos_tce_storage::validator::ValidatorStore; | ||
use topos_test_sdk::{ | ||
certificates::create_certificate_chain, | ||
constants::{SOURCE_SUBNET_ID_1, TARGET_SUBNET_ID_1}, | ||
crypto::message_signer, | ||
storage::create_validator_store, | ||
}; | ||
|
||
use crate::{ | ||
double_echo::broadcast_state::BroadcastState, event::ProtocolEvents, | ||
sampler::SubscriptionsView, task_manager::task::Task, | ||
}; | ||
|
||
#[rstest] | ||
#[test_log::test(tokio::test)] | ||
#[timeout(Duration::from_secs(1))] | ||
async fn start_with_ungossiped_cert( | ||
#[future(awt)] | ||
#[from(create_validator_store)] | ||
validatore_store: Arc<ValidatorStore>, | ||
message_signer: Arc<MessageSigner>, | ||
) { | ||
let certificate = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1) | ||
.pop() | ||
.unwrap() | ||
.certificate; | ||
let certificate_id = certificate.id; | ||
let validator_id = ValidatorId::default(); | ||
let thresholds = topos_config::tce::broadcast::ReliableBroadcastParams { | ||
echo_threshold: 1, | ||
ready_threshold: 1, | ||
delivery_threshold: 1, | ||
}; | ||
let (event_sender, mut event_receiver) = mpsc::channel(2); | ||
let (broadcast_sender, _) = broadcast::channel(1); | ||
let need_gossip = true; | ||
let subscriptions = SubscriptionsView::default(); | ||
|
||
let broadcast_state = BroadcastState::new( | ||
certificate, | ||
validator_id, | ||
thresholds.echo_threshold, | ||
thresholds.ready_threshold, | ||
thresholds.delivery_threshold, | ||
event_sender, | ||
subscriptions, | ||
need_gossip, | ||
message_signer, | ||
); | ||
|
||
let (task, _ctx) = Task::new( | ||
certificate_id, | ||
broadcast_state, | ||
validatore_store, | ||
broadcast_sender, | ||
); | ||
|
||
let _handle = spawn(task.into_future()); | ||
|
||
let event = event_receiver.recv().await; | ||
assert!(matches!( | ||
event, | ||
Some(ProtocolEvents::Broadcast { | ||
certificate_id: id | ||
}) if id == certificate_id | ||
)); | ||
|
||
let event = event_receiver.recv().await; | ||
assert!(matches!( | ||
event, | ||
Some(ProtocolEvents::Gossip { | ||
cert: Certificate { id, .. } | ||
}) if id == certificate_id | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.