From 318fd1d094cfb55d56f7db494231778c3abcca83 Mon Sep 17 00:00:00 2001 From: plebhash Date: Sat, 1 Feb 2025 11:36:32 -0300 Subject: [PATCH] WIP add *_survives_downstream_disconnect integration tests --- .../tests-integration/tests/jd_integration.rs | 14 ++++++++++ .../tests/pool_integration.rs | 27 ++++++++++++++++++ .../tests/translator_integration.rs | 28 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/roles/tests-integration/tests/jd_integration.rs b/roles/tests-integration/tests/jd_integration.rs index 58b98d098..acdd8c4ec 100644 --- a/roles/tests-integration/tests/jd_integration.rs +++ b/roles/tests-integration/tests/jd_integration.rs @@ -35,3 +35,17 @@ async fn jds_should_not_panic_if_jdc_shutsdown() { let (_jdc, _jdc_addr) = start_jdc(pool_addr, tp_addr, sniffer_addr).await; assert_common_message!(sniffer.next_message_from_downstream(), SetupConnection); } + +// This test makes sure that JDS will not stop listening after one +// downstream client disconnects +#[tokio::test] +async fn jds_survives_downstream_disconnect() { + todo!() +} + +// This test makes sure that JDC will not stop listening after one +// downstream client disconnects +#[tokio::test] +async fn jdc_survives_downstream_disconnect() { + todo!() +} \ No newline at end of file diff --git a/roles/tests-integration/tests/pool_integration.rs b/roles/tests-integration/tests/pool_integration.rs index 94c832a0d..82a95dee9 100644 --- a/roles/tests-integration/tests/pool_integration.rs +++ b/roles/tests-integration/tests/pool_integration.rs @@ -122,3 +122,30 @@ async fn header_timestamp_value_assertion_in_new_extended_mining_job() { "The `minntime` field of the second NewExtendedMiningJob does not match the `header_timestamp`!" ); } + +// This test makes sure that Pool will not stop listening after one +// downstream client disconnects +#[tokio::test] +async fn pool_survives_downstream_disconnect() { + let (_tp, tp_addr) = start_template_provider(None).await; + let (pool, pool_addr) = start_pool(Some(tp_addr)).await; + + // emulate first downstream + let downstream_a = std::net::TcpStream::connect(pool_addr).unwrap(); + + // emulate second downstream + let _downstream_b = std::net::TcpStream::connect(pool_addr).unwrap(); + + // wait a bit to make sure the TCP sockets are processed + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + + // kill downstream_a + downstream_a.shutdown(std::net::Shutdown::Both).unwrap(); + drop(downstream_a); + + // wait a bit to make sure the TCP sockets are processed + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + + // pool still listening + assert!(pool.is_listening()); +} \ No newline at end of file diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index 6aabfb4ca..54cea0309 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -44,3 +44,31 @@ async fn translation_proxy() { ) .await; } + +// This test makes sure that tProxy will not stop listening after one +// downstream client disconnects +#[tokio::test] +async fn tproxy_survives_downstream_disconnect() { + let (_tp, tp_addr) = start_template_provider(None).await; + let (_pool, pool_addr) = start_pool(Some(tp_addr)).await; + let (tproxy, tproxy_addr) = start_sv2_translator(pool_addr).await; + + // emulate first downstream + let downstream_a = std::net::TcpStream::connect(tproxy_addr).unwrap(); + + // emulate second downstream + let _downstream_b = std::net::TcpStream::connect(tproxy_addr).unwrap(); + + // wait a bit to make sure the TCP sockets are processed + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + + // kill downstream_a + downstream_a.shutdown(std::net::Shutdown::Both).unwrap(); + drop(downstream_a); + + // wait a bit to make sure the TCP sockets are processed + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + + // tproxy still listening + assert!(tproxy.is_listening()); +} \ No newline at end of file