Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test JDC shutdown behavior #1348

Open
jbesraa opened this issue Jan 16, 2025 · 2 comments · May be fixed by #1360
Open

Test JDC shutdown behavior #1348

jbesraa opened this issue Jan 16, 2025 · 2 comments · May be fixed by #1360

Comments

@jbesraa
Copy link
Contributor

jbesraa commented Jan 16, 2025

#1321
Introduced a shutdown object to JobDeclaratorClient but add a unit test to cover its functionality.

Ideally something like the following should be added as a unit test:

#[cfg(test)]
mod tests {
    use ext_config::{Config, File, FileFormat};

    use crate::*;

    #[test]
    fn test_shutdown() {
        let config_path = "config-examples/jdc-config-hosted-example.toml";
        let config: ProxyConfig = match Config::builder()
            .add_source(File::new(config_path, FileFormat::Toml))
            .build()
        {
            Ok(settings) => match settings.try_deserialize::<ProxyConfig>() {
                Ok(c) => c,
                Err(e) => {
                    dbg!(&e);
                    return;
                }
            },
            Err(e) => {
                dbg!(&e);
                return;
            }
        };
        let jdc = JobDeclaratorClient::new(config.clone());
        let cloned = jdc.clone();
        tokio::spawn(async move {
            cloned.start().await;
        });
        jdc.shutdown();
        let ip = config.downstream_address.clone();
        let port = config.downstream_port;
        let jdc_addr = format!("{}:{}", ip, port);
        assert!(std::net::TcpListener::bind(jdc_addr).is_ok());
    }
}
@jbesraa
Copy link
Contributor Author

jbesraa commented Jan 16, 2025

This is mainly raised because of this test https://github.com/stratum-mining/stratum/blob/main/test/message-generator/test/jds-do-not-panic-if-jdc-close-connection/jds-do-not-panic-if-jdc-close-connection.json

We can migrate this test easily to ITF with the following:

#[tokio::test]
async fn jds_should_not_panic_if_jdc_shutsdown() {
    let (_tp, tp_addr) = start_template_provider(None).await;
    let (_pool, pool_addr) = start_pool(Some(tp_addr)).await;
    let (_jds, jds_addr) = start_jds(tp_addr).await;
    let (jdc, jdc_addr) = start_jdc(vec![pool_addr], tp_addr, jds_addr).await;
    // This shutdown behavior is not working as expected as `jdc_addr` is not available
    jdc.shutdown();
    let ret = tokio::net::TcpListener::bind(jdc_addr).await;
    dbg!(&ret);
    assert!(ret.is_ok());
    let (sniffer, sniffer_addr) = start_sniffer("0".to_string(), jds_addr, false, None).await;
    let (_jdc, _jdc_addr) = start_jdc(vec![pool_addr], tp_addr, sniffer_addr).await;
    assert_common_message!(sniffer.next_message_from_downstream(), SetupConnection);
}

@Shourya742
Copy link
Contributor

This is mainly raised because of this test https://github.com/stratum-mining/stratum/blob/main/test/message-generator/test/jds-do-not-panic-if-jdc-close-connection/jds-do-not-panic-if-jdc-close-connection.json

We can migrate this test easily to ITF with the following:

#[tokio::test]
async fn jds_should_not_panic_if_jdc_shutsdown() {
    let (_tp, tp_addr) = start_template_provider(None).await;
    let (_pool, pool_addr) = start_pool(Some(tp_addr)).await;
    let (_jds, jds_addr) = start_jds(tp_addr).await;
    let (jdc, jdc_addr) = start_jdc(vec![pool_addr], tp_addr, jds_addr).await;
    // This shutdown behavior is not working as expected as `jdc_addr` is not available
    jdc.shutdown();
    let ret = tokio::net::TcpListener::bind(jdc_addr).await;
    dbg!(&ret);
    assert!(ret.is_ok());
    let (sniffer, sniffer_addr) = start_sniffer("0".to_string(), jds_addr, false, None).await;
    let (_jdc, _jdc_addr) = start_jdc(vec![pool_addr], tp_addr, sniffer_addr).await;
    assert_common_message!(sniffer.next_message_from_downstream(), SetupConnection);
}

will add this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants