use std::time::Duration; use tracing::{Level, debug}; use ubisync::{Ubisync, config::Config, state::types::{ElementContent, Element, ElementId}}; #[tokio::test(flavor = "multi_thread")] async fn two_nodes_element_creation() { tracing_subscriber::fmt().pretty().with_max_level(Level::DEBUG).init(); // Two nodes need to bind to different ports let mut c2 = Config::default(); c2.api_config.port = Some(9982); let ubi1 = Ubisync::new(&Config::default()).await.unwrap(); let ubi2 = Ubisync::new(&c2).await.unwrap(); ubi1.add_peer_from_id(ubi2.get_destination().unwrap().into()).unwrap(); let http_client = reqwest::Client::new(); let test_element_content = ElementContent::Text("Text".to_string()); let put_resp = http_client.put(&format!("http://localhost:9981/v0/element")).json(&test_element_content).send().await.unwrap(); debug!("{:?}", &put_resp); let put_resp_text = put_resp.text().await.expect("No put response body"); debug!("{}", put_resp_text); let id = serde_json::from_str::(&put_resp_text).expect("Could not deserialize ElementId"); tokio::time::sleep(Duration::from_millis(3000)).await; let get_resp = http_client.get(&format!("http://localhost:9982/v0/element/{}", Into::::into(&id))).send().await.expect("Get request failed"); let get_resp_text = get_resp.text().await.expect("No get request body"); debug!("{}", get_resp_text); let received_element = serde_json::from_str::(&get_resp_text).expect("Could not deserialize Element"); debug!("Other node received this element: {:?}", received_element); assert_eq!(&test_element_content, received_element.content()); std::process::exit(0); }