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

[CHORE] Simplify e2e test setup with shared logic #456

Open
brooksmtownsend opened this issue Oct 18, 2024 · 1 comment
Open

[CHORE] Simplify e2e test setup with shared logic #456

brooksmtownsend opened this issue Oct 18, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest This issue is specifically designated as a good issue for Hacktoberfest rust Pull requests that update Rust code

Comments

@brooksmtownsend
Copy link
Member

All of the e2e tests currently start with some variation of this code in order to setup the proper lattices & expected number of hosts:

    let mut client_info = ClientInfo::new(manifest_dir, compose_file).await;
    client_info
        .add_ctl_client(SHARED_COMPONENTS_LATTICE, None)
        .await;
    client_info.add_wadm_client(SHARED_COMPONENTS_LATTICE).await;
    client_info
        .add_ctl_client(SHARED_PROVIDERS_LATTICE, None)
        .await;
    client_info.add_wadm_client(SHARED_PROVIDERS_LATTICE).await;
    client_info.add_ctl_client(INVALID_TEST_LATTICE, None).await;
    client_info.add_wadm_client(INVALID_TEST_LATTICE).await;
    client_info.launch_wadm().await;

    // Wait for the first event on the lattice prefix before we start deploying and checking
    // statuses. Wadm can absolutely handle hosts starting before you start the wadm process, but the first event
    // on the lattice will initialize the lattice monitor and for the following test we quickly assert things.
    let mut sub = client_info
        .client
        .subscribe("wasmbus.evt.*.>".to_string())
        .await
        .expect("Should be able to subscribe to default events");
    // Host heartbeats happen every 30 seconds, if we don't get a heartbeat in 2 minutes, bail.
    let _ = tokio::time::timeout(std::time::Duration::from_secs(120), sub.next())
        .await
        .expect("should have received a host heartbeat event before timeout");

    // Wait for hosts to start
    let mut did_start = false;
    for _ in 0..10 {
        match (
            client_info
                .ctl_client(SHARED_COMPONENTS_LATTICE)
                .get_hosts()
                .await,
            client_info
                .ctl_client(SHARED_PROVIDERS_LATTICE)
                .get_hosts()
                .await,
        ) {
            (Ok(hosts_one), Ok(hosts_two)) if hosts_one.len() == 2 && hosts_two.len() == 2 => {
                eprintln!(
                    "Hosts {}/2, {}/2 currently available",
                    hosts_one.len(),
                    hosts_two.len()
                );
                did_start = true;
                break;
            }
            (Ok(hosts_one), Ok(hosts_two)) => {
                eprintln!(
                    "Waiting for all hosts to be available, {}/2, {}/2 currently available",
                    hosts_one.len(),
                    hosts_two.len()
                );
            }
            (Err(e), _) | (_, Err(e)) => {
                eprintln!("Error when fetching hosts: {e}",)
            }
        }
        tokio::time::sleep(Duration::from_secs(1)).await;
    }

    if !did_start {
        panic!("Hosts didn't start")
    }

What would be really nice is for the common e2e logic to have a helper function that takes a list of lattices & expected hosts in that lattice to simplify the setup of e2e tests.

This is a good first issue for someone looking to make an impact on test reusability 😄

@brooksmtownsend brooksmtownsend added enhancement New feature or request good first issue Good for newcomers hacktoberfest This issue is specifically designated as a good issue for Hacktoberfest rust Pull requests that update Rust code labels Oct 18, 2024
Copy link

stale bot commented Dec 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this has been closed too eagerly, please feel free to tag a maintainer so we can keep working on the issue. Thank you for contributing to wasmCloud!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest This issue is specifically designated as a good issue for Hacktoberfest rust Pull requests that update Rust code
Projects
None yet
Development

No branches or pull requests

1 participant