summaryrefslogtreecommitdiffstats
path: root/src/simtest/timing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/simtest/timing.rs')
-rw-r--r--src/simtest/timing.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/simtest/timing.rs b/src/simtest/timing.rs
index 20ad15c..72c6c05 100644
--- a/src/simtest/timing.rs
+++ b/src/simtest/timing.rs
@@ -414,3 +414,77 @@ async fn forgotten_node_that_is_alive_cancels_its_record() {
}
sim.wait_converged(&[a, b, c], SOON).await;
}
+
+/// A transport that only connects out: it publishes no address, as a libp2p node
+/// without a listen address (`topology::refresh`, `outbound`).
+struct OutboundOnly(std::sync::Arc<dyn crate::transport::Transport>);
+
+#[async_trait::async_trait]
+impl crate::transport::Transport for OutboundOnly {
+ fn local_id(&self) -> &str {
+ self.0.local_id()
+ }
+ fn is_peer_id(&self, id: &str) -> bool {
+ self.0.is_peer_id(id)
+ }
+ fn delivery_limit(&self) -> Duration {
+ self.0.delivery_limit()
+ }
+ fn local_addresses(&self) -> Vec<String> {
+ Vec::new()
+ }
+ async fn resolve_seed(&self, seed: &str) -> anyhow::Result<String> {
+ self.0.resolve_seed(seed).await
+ }
+ fn encode(
+ &self,
+ peer: &str,
+ message: &ParsedMessage,
+ ) -> anyhow::Result<crate::transport::EncodedMessage> {
+ self.0.encode(peer, message)
+ }
+ async fn send_encoded(&self, message: &crate::transport::EncodedMessage) -> anyhow::Result<()> {
+ self.0.send_encoded(message).await
+ }
+ async fn start_consumer(
+ &self,
+ handler: crate::transport::MessageHandler,
+ ) -> anyhow::Result<()> {
+ self.0.start_consumer(handler).await
+ }
+ async fn wait_for_exit(&self) -> std::io::Result<std::process::ExitStatus> {
+ self.0.wait_for_exit().await
+ }
+}
+
+/// A member with no address (it only connects out) is in nobody's graph but its own:
+/// those it picked keep it as a neighbour, so their changes reach it too, not only
+/// answers to its own.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_member_that_only_connects_out_gets_changes() {
+ let sim = Sim::new(7);
+ let a = sim.start("a", &[], Start::Genesis);
+ let b = sim.start_with("b", &["a"], Start::Join, |config| {
+ config.transport = std::sync::Arc::new(OutboundOnly(config.transport.clone()));
+ });
+ let c = sim.start("c", &["a"], Start::Join);
+ let (a, b, c) = (&a, &b, &c);
+ sim.wait_ready(&[a, b, c], SOON).await;
+ // Once b is listed (without an address), the member list no longer makes it a's
+ // or c's neighbour.
+ sim.wait_until("b is listed", SOON, move || async move {
+ read(a, "_continuum/members/b").await.is_some()
+ && read(c, "_continuum/members/b").await.is_some()
+ })
+ .await;
+ sim.wait_until("a and c keep b", SOON, move || async move {
+ has_neighbour(a, "b") && has_neighbour(c, "b")
+ })
+ .await;
+ write(a, "from/a", json!(1)).await;
+ write(c, "from/c", json!(3)).await;
+ sim.wait_until("b has a's and c's writes", SOON, move || async move {
+ read(b, "from/a").await == Some(json!(1)) && read(b, "from/c").await == Some(json!(3))
+ })
+ .await;
+}