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

Add Support for cargo nextest #3920

Closed
wants to merge 323 commits into from
Closed

Add Support for cargo nextest #3920

wants to merge 323 commits into from

Conversation

spigaz
Copy link
Contributor

@spigaz spigaz commented Apr 10, 2024

This is still work in progress:
https://nexte.st/book/custom-test-harnesses.html

Progress

  • Added support for -h and --help w/tests
  • Added support for -V and --version w/tests
  • Added support for --list --format terse w/tests
  • Added support for --list --format --ignored w/tests
  • Add support for <test-name> --nocapture --exact w/tests
  • Reinstated support for --include-ignored w/tests
  • Reinstated support for --skip name w/tests
  • Reinstated support for --skip=name w/tests
  • Reinstated support for filter w/tests
  • Solved the temporary directory conflict caused by the concurrent invocation
  • Update --include-ignored to use clap
  • Update --skip name to use clap
  • Added tests to execute tests on nodejs
  • Fixed support and added tests to execute tests on deno
  • Add tests to execute tests on chrome
  • Added tests to execute tests on firefox
  • Add tests to execute tests on safari
  • Add tests to execute tests on edge
  • Add tests with cargo nextest invoking wasm-bindgen-test-runner
  • Use feature! macro to simplify testing
  • Use feature! test_mode parameter to execute the specification over all the test_modes

Updated to use clap

  • docopt was used already in wasm-bindgen, but its unmaintained https://github.com/docopt/docopt.rs and recommends clap or structopt, but structopt's docs state "As clap v3 is now out, and the structopt features are integrated into (almost as-is), structopt is now in maintenance mode"

Updated the macro wasm_bindgen_test

  • To allow listing handling as required by nextext

Testing

  • I wasn't sure what was the best place to put the tests in, because of the custom test runner in the cli crate, so I placed them on main tests folder.

  • I used a variation of BDD that I use for many years now.
    -- Although it seems a bit more verbose, it makes writing tests a lot simpler and faster, anyone can understand them and add new ones.
    -- When something breaks its very easy to understand why.
    -- Although conter-intuitive, in practice I have found that they are a lot easier to update on refactors.

Overhead

  • When used from cargo nextest the overhead is pretty real, as it has to load the runtime and the wasm into it, so it can be a lot, but it runs them in parallel, so it makes up for it on tests that take a long to execute.

Architecture:

  • I would prefer to organize the code into:
    -- a folder with the CLI and environment stuff
    -- a folder with the wasm handling
    -- a folder with the runtimes

@daxpedda
Copy link
Collaborator

Apologies for the delay, I was on vacation, still catching up.
Planning to take a look tomorrow!

@spigaz
Copy link
Contributor Author

spigaz commented Apr 18, 2024

That's okay!
I still have one missing piece ahead to get it working with cargo nextest, so its fine.

@spigaz
Copy link
Contributor Author

spigaz commented Apr 22, 2024

Well its working, actually its my second version working, the fist one used locks.

But according to the the library documentation it shouldn't work (at least cross-platform):

See the tests in lib.rs for cross-platform lock behavior that may be relied upon
// Concurrent shared access is OK, but not shared and exclusive.
// Once all shared file locks are dropped, an exclusive lock may be created;
// No other access is possible once an exclusive lock is created.
// Once the exclusive lock is dropped, the second file is able to create a lock.
https://github.com/danburkert/fs2-rs/blob/master/src/lib.rs

Anyway, the overhead was as bad as I expected, as each test execution now requires the same overhead as a complete assembly, I only tested on firefox so far, about 12-13s each, thermal throttled.

But when tests take longer than the overhead, the extra cores start to payoff.

I'm having thermal throttling issues, but my speed boost might be around 3x when I have the tests configured for very heavy parameters, its a property based testing variation.

@spigaz spigaz changed the title WIP: Add Support for cargo nextest Add Support for cargo nextest Apr 23, 2024
@spigaz
Copy link
Contributor Author

spigaz commented Apr 27, 2024

I was waiting for your review, because as I do more tests, I end up finding more stuff to fix, making the review harder on you. Sorry.

I ended up fixing support for deno, not sure why, but it was for sure broken.
I added some tests and updated the github action, so now its under control.
You can cherry pick that if you want.

@spigaz spigaz changed the title Add Support for cargo nextest Add Support for cargo nextest && Fixed support for deno Apr 27, 2024
@spigaz
Copy link
Contributor Author

spigaz commented May 24, 2024

@daxpedda I have been trying to create a macro to simplify the tests, this will be particular useful for tests that should be run over the different runtimes supported.

I'm still working on the syntax, as the macro by itself, is allowing different usage patterns.

But right now, this is the format already working:

feature! {
    given_there_is_an_assembly_with_one_failing_test();
    when_wasm_bindgen_test_runner_is_invoked_with_the_option("-V");

    "Outputs the version" {
        then_the_standard_output_should_have(
            &format!("wasm-bindgen-test-runner {}", env!("CARGO_PKG_VERSION")),
        );
    }

    "Returns success" {
        then_success_should_have_been_returned();
    }
}

It expands to two tests

#[test]
fn outputs_the_wasm_bindgen_test_runner_version_information_feature() {
    let mut context = Context::new();
    given_there_is_an_assembly_with_one_failing_test(&mut context);
    when_wasm_bindgen_test_runner_is_invoked_with_the_option(&mut context, "-V");
    then_the_standard_output_should_have(
        &context,
        &format!("wasm-bindgen-test-runner {}", env!("CARGO_PKG_VERSION")),
    );
}

#[test]
fn returns_success_feature() {
    let mut context = Context::new();
    given_there_is_an_assembly_without_anything(&mut context);
    when_wasm_bindgen_test_runner_is_invoked_with_the_option(&mut context, "-V");
    then_success_should_have_been_returned(&context);
}

If the target platform is wasm it uses [wasm_bindgen_test::wasm_bindgen_test] instead.

This allows for a more compact file, because there are sometimes 5-7 different outcomes for a single execution context

The idea is by default to respect the single outcome, allowing easy troubleshooting of regressions, but its possible to aggregate the executions on CI for faster execution times.

spigaz added 21 commits May 24, 2024 19:18
…est summary to invocation with_an_assembly without_arguments level_1 with_one_successful_test.
…ation with_an_assembly without_arguments level_1 with_one_successful_test.
…st to invocation with_an_assembly without_arguments level_1 with_one_successful_test.
…cation with_an_assembly without_arguments level_1 with_one_successful_test.
…t summary to invocation with_an_assembly without_arguments level_1 with_one_successful_test.
…est summary to invocation with_an_assembly without_arguments level_2 with_one_successful_test.
…st to invocation with_an_assembly without_arguments level_2 with_one_successful_test.
…cation with_an_assembly without_arguments level_2 with_one_successful_test.
…t summary to invocation with_an_assembly without_arguments level_2 with_one_successful_test.
…ation with_an_assembly without_arguments level_2 with_one_successful_test.
…mbly with_arguments --list --format terse default tests into level_0.
… to support --list --format terse and --list --format terse --ignored.
…terse format to the invocation with_an_assembly with_arguments --list --format terse.
…terse format to the invocation with_an_assembly with_arguments --list --format terse default level_2.
…nvocation with_an_assembly with_arguments --list --format terse default level_1.
…nvocation with_an_assembly with_arguments --list --format terse default level_2.
@spigaz
Copy link
Contributor Author

spigaz commented Jul 13, 2024

@daxpedda I understand your reasoning, and to be honest, I'm trying to narrow things to make it easier for you to review.

The problem is that cargo nextest stresses wasm-bindgen-test a lot, in my repo, 771 times, that means that all the instability issues pop up.

Anyway for now, I'm not being able to trigger issues with any of the supported runtimes...

I was finally able to remove the hacks I added to get cargo nextest working, because of the shared directory, using a ResourceCoordinator.

I just have some minor things, then I'm going to let you take the lead on this and I can create as much PRs as necessary.

spigaz added 19 commits July 13, 2024 19:54
…n_test_runner_env_set from wasm-bindgen_test_runner_command.
@spigaz spigaz changed the title Add Support for cargo nextest && Fixed support for deno Add Support for cargo nextest Jul 22, 2024
@ifiokjr
Copy link

ifiokjr commented Sep 29, 2024

This looks great! Has it stalled?

@spigaz
Copy link
Contributor Author

spigaz commented Sep 29, 2024

This looks great! Has it stalled?

@ifiokjr No, its done. Although now I have some merge conflicts to solve.

I just have been working on a way to get the tests to be more intuitive, to see if it eases the merging.

I just didn't pushed it, because it didn't seem to be a priority for anyone and I would break the existing tests, but if its a priority for you, I can try to speed up things...

@daxpedda
Copy link
Collaborator

Done in #4356.

@daxpedda daxpedda closed this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Waiting for author to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants