Skip to content

Commit

Permalink
chore: Clean up + Starting swap integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Apr 22, 2024
1 parent 75efd72 commit 0305627
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions kit/tests/swap_integration.rs
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");
}
}
}

0 comments on commit 0305627

Please sign in to comment.