-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Clean up + Starting swap integration tests
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::time::Duration; | ||
|
||
use arbiter_engine::messager::To; | ||
use dfmm_kit::behaviors::MessageTypes; | ||
use futures_util::StreamExt; | ||
use tracing::{info, warn}; | ||
include!("common.rs"); | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 5)] | ||
async fn run_updater_constant_sum() { | ||
log(Level::DEBUG); | ||
|
||
let mut world = World::new("test"); | ||
let messager = world.messager.for_agent("test"); | ||
|
||
spawn_deployer(&mut world); | ||
spawn_token_admin(&mut world); | ||
// spawn_constant_sum_creator(&mut world); | ||
spawn_constant_sum_updater(&mut world); | ||
|
||
let task: tokio::task::JoinHandle<()> = tokio::spawn(async move { | ||
// Sleep because the world needs to give all of the agents time to build their | ||
// receivers. TODO: This is a bit of a hack and we could honestly make | ||
// the `World::run` better to handle this, but this works for now. | ||
tokio::time::sleep(Duration::from_millis(2000)).await; | ||
// let mut count = 0; | ||
// let mut stream = messager.stream().unwrap(); | ||
// while let Some(message) = stream.next().await { | ||
// match serde_json::from_str::<MessageTypes<ConstantSumPool>>(&message.data) { | ||
// Ok(data) => { | ||
// info!("deserialized data: {:#?}", data); | ||
// match data { | ||
// MessageTypes::Deploy(_) => continue, | ||
// MessageTypes::Create(_) => continue, | ||
// MessageTypes::TokenAdmin(_) => continue, | ||
// MessageTypes::Update(params) => { | ||
// info!("successfully updated the params to {:?}", params); | ||
// let mock_data = constant_sum_parameters(); | ||
// assert_eq!(params, mock_data[count]); | ||
// if count >= 2 { | ||
// break; | ||
// } else { | ||
// count += 1; | ||
// } | ||
// } | ||
// } | ||
// } | ||
// Err(_) => { | ||
// warn!( | ||
// "Failed to parse message data into ConstantSumParams, instead got: {:#?}", | ||
// message.data | ||
// ); | ||
// continue; | ||
// } | ||
// } | ||
// } | ||
}); | ||
|
||
// Setup a timeout for the test to ensure it does not run indefinitely. | ||
let timeout_duration = Duration::from_secs(10); // Adjust the timeout as needed. | ||
|
||
tokio::select! { | ||
_ = world.run() => { | ||
panic!("World run unexpectedly completed"); | ||
}, | ||
result = task => { | ||
match result { | ||
Ok(_) => println!("Task completed successfully and test should pass."), | ||
Err(e) => panic!("Task encountered an error: {:?}", e), | ||
} | ||
}, | ||
_ = tokio::time::sleep(timeout_duration) => { | ||
panic!("Test timed out"); | ||
} | ||
} | ||
} |