reactive_graph_client/client/runtime/remotes/queries/
get_all.rs

1#[cynic::schema_for_derives(file = r#"../../schema/graphql/reactive-graph-runtime-schema.graphql"#, module = "crate::schema_runtime::schema")]
2pub mod queries {
3    use crate::InstanceInfo;
4
5    #[derive(Debug, cynic::QueryFragment)]
6    #[cynic(graphql_type = "Query")]
7    pub struct GetAllRemotes {
8        pub remotes: Vec<InstanceInfo>,
9    }
10
11    pub fn get_all() -> cynic::Operation<GetAllRemotes, ()> {
12        use cynic::QueryBuilder;
13        GetAllRemotes::build(())
14    }
15}
16
17#[cfg(all(test, feature = "integration-tests"))]
18pub mod test {
19    use crate::ReactiveGraphClient;
20    use reactive_graph_runtime_api::Runtime;
21    use reactive_graph_runtime_impl::RuntimeBuilder;
22    use std::sync::Arc;
23    use std::time::Duration;
24    use tokio::time::sleep;
25
26    #[tokio::test(flavor = "multi_thread")]
27    async fn test_get_all_remotes() {
28        RuntimeBuilder::new()
29            .ignore_config_files()
30            .disable_all_plugins(true)
31            .pick_free_port()
32            .init()
33            .await
34            .post_init()
35            .await
36            .spawn()
37            .await
38            .with_runtime(|runtime: Arc<dyn Runtime + Send + Sync>| async move {
39                sleep(Duration::from_millis(2000)).await;
40
41                let remotes_manager = runtime.get_remotes_manager();
42
43                let rt_address = runtime.address();
44
45                // RT: Create remote
46                remotes_manager.add(&rt_address).await.expect("Failed to add self to list of remotes");
47
48                let rt_remotes = remotes_manager.get_all();
49
50                // Client: Connect to self and get all remotes
51                let client = ReactiveGraphClient::new(rt_address).expect("Cannot create client");
52                let remotes = client.runtime().remotes().get_all().await.expect("Failed to get all remotes");
53
54                // Expect that the remotes of the runtime are the same
55                assert_eq!(remotes.len(), 1);
56                assert_eq!(remotes, rt_remotes);
57            })
58            .await
59            .stop()
60            .await
61            .pre_shutdown()
62            .await
63            .shutdown()
64            .await;
65    }
66}