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

Pass thru test-options opts to rspec to support running with Guard (for failure-exit-code) #20

Closed
wants to merge 14 commits into from

Conversation

rsanheim
Copy link

@rsanheim rsanheim commented Mar 28, 2022

For #14: Allow passing custom test options via the --test-options flag so that turbo_tests works with Guard. I believe guard passes thru the custom exit code to parallel_tests so it can properly capture failure exit codes and keep rerunning things and not abort...and turbo tests needs the same thing to work with guard.

This required tweaking how the runner reports exit statuses back to the CLI -- I wasn't super sure about that piece and how it will interact with the threads, but it is reporting the correct exit code for the limited specs I've added.

I chose not to support extra options via -- for a few reasons:

  • I wanted to get the custom_exit_code piece working in the simplest way possible to start to support guard usage 😁
  • When I attempted it initially, I was hitting issues with all sorts of edge cases where you may or may not have multiple -- in the command line, and then making sure you merge in things like tags. If I had more time I would refactor the arg parsing and test it much better in isolation (probably much like parallel-tests), and then work on getting that state to the runner in a nice, clean way.

Currently all specs are passing for me locally - I thought the pending specs were failing but that was user error, I had some errant whitespace added. ✅

I also refactored the specs a bit to be easier to read with more of the state / setup close to the actual thing being tested and asserted. Hope this all makes sense to you, let me know what you think @ilyazub.

Copy link
Collaborator

@ilyazub ilyazub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rsanheim! WDYT about support for passing options --?

Comment on lines 50 to 52
opts.on("-o", "--test-options '[OPTIONS]'", "execute test commands with those options") do |arg|
test_options << arg.strip
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 What if -- can be also used for test options similar to parallel_tests: https://github.com/grosser/parallel_tests/blob/b85a17ebd9cf920b2052623b28f0839bc35885de/lib/parallel_tests/cli.rb#L322-L339?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heya I updated the PR body w/ more context around this. tldr: I think it would be good for future PRs 😁

@rsanheim rsanheim marked this pull request as ready for review April 6, 2022 03:50
@rsanheim rsanheim changed the title (draft) pass thru command line opts to rspec Pass thru test-options opts to rspec to support running with Guard (for failure-exit-code) Apr 6, 2022
Copy link
Author

@rsanheim rsanheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some notes

else
exit 1
end
exit exitstatus
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now just report the exitstatus that comes back from the Runner directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

if @reporter.failed_examples.empty? && wait_threads.map(&:value).all?(&:success?)
SUCCESS_EXIT_CODE
else
wait_threads.max { |value| value.exitstatus }.value.exitstatus
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails with undefined method 'exitstatus' for #<Process::Waiter:0x0000000002588318 dead> (NoMethodError) when I test it on a big test suite.

Finished in 4 minutes 38.4 seconds (files took 26.8 seconds to load)
16001 examples, 11 failures, 1 pending, 2 errors occurred outside of examples

# ...

bundler: failed to load command: turbo_tests (/home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests)
Traceback (most recent call last):
        22: from /home/serpapi/.rbenv/versions/2.7.2/bin/bundle:25:in `<main>'
        21: from /home/serpapi/.rbenv/versions/2.7.2/bin/bundle:25:in `load'
        20: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/exe/bundle:37:in `<top (required)>'
        19: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
        18: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/exe/bundle:49:in `block in <top (required)>'
        17: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:25:in `start'
        16: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
        15: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:31:in `dispatch'
        14: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
        13: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        12: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        11: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:477:in `exec'
        10: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:23:in `run'
         9: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:58:in `kernel_load'
         8: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:58:in `load'
         7: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:25:in `<top (required)>'
         6: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:25:in `load'
         5: from /home/serpapi/Workspace/turbo_tests/bin/turbo_tests:11:in `<top (required)>'
         4: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/cli.rb:101:in `run'
         3: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:41:in `run'
         2: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `run'
         1: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `max'
/home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `block in run': undefined method `exitstatus' for #<Process::Waiter:0x0000000002588318 dead> (NoMethodError)

@@ -1,9 +1,62 @@
RSpec.describe TurboTests::CLI do
subject(:output) { `bundle exec turbo_tests -f d #{fixture}`.strip }
let(:bin) { Pathname(__dir__).join("../bin/turbo_tests").expand_path }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, but nice to bypass bundler overhead if we can.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bin used?

@rsanheim
Copy link
Author

rsanheim commented Apr 6, 2022

Hey @ilyazub, I have this passing for test-options and ready for another review pass. Lemme know what you think!

@rsanheim rsanheim requested a review from ilyazub April 6, 2022 03:54
Copy link
Collaborator

@ilyazub ilyazub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsanheim Cool, thanks for your work! Sorry for the late review.

For me it fails with undefined method 'exitstatus' for #<Process::Waiter:0x0000000002588318 dead> (NoMethodError) when I test it on a big test suite. I'll try to debug it too.

else
exit 1
end
exit exitstatus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

@@ -1,9 +1,62 @@
RSpec.describe TurboTests::CLI do
subject(:output) { `bundle exec turbo_tests -f d #{fixture}`.strip }
let(:bin) { Pathname(__dir__).join("../bin/turbo_tests").expand_path }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bin used?

if @reporter.failed_examples.empty? && wait_threads.map(&:value).all?(&:success?)
SUCCESS_EXIT_CODE
else
wait_threads.max { |value| value.exitstatus }.value.exitstatus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails with undefined method 'exitstatus' for #<Process::Waiter:0x0000000002588318 dead> (NoMethodError) when I test it on a big test suite.

Finished in 4 minutes 38.4 seconds (files took 26.8 seconds to load)
16001 examples, 11 failures, 1 pending, 2 errors occurred outside of examples

# ...

bundler: failed to load command: turbo_tests (/home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests)
Traceback (most recent call last):
        22: from /home/serpapi/.rbenv/versions/2.7.2/bin/bundle:25:in `<main>'
        21: from /home/serpapi/.rbenv/versions/2.7.2/bin/bundle:25:in `load'
        20: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/exe/bundle:37:in `<top (required)>'
        19: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
        18: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/exe/bundle:49:in `block in <top (required)>'
        17: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:25:in `start'
        16: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
        15: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:31:in `dispatch'
        14: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
        13: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        12: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        11: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli.rb:477:in `exec'
        10: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:23:in `run'
         9: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:58:in `kernel_load'
         8: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.2.27/lib/bundler/cli/exec.rb:58:in `load'
         7: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:25:in `<top (required)>'
         6: from /home/serpapi/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:25:in `load'
         5: from /home/serpapi/Workspace/turbo_tests/bin/turbo_tests:11:in `<top (required)>'
         4: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/cli.rb:101:in `run'
         3: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:41:in `run'
         2: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `run'
         1: from /home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `max'
/home/serpapi/Workspace/turbo_tests/lib/turbo_tests/runner.rb:107:in `block in run': undefined method `exitstatus' for #<Process::Waiter:0x0000000002588318 dead> (NoMethodError)

@john-h-k
Copy link

Can I take over this work?

@hartator
Copy link

Can I take over this work?

Sure, PRs are always welcomed. 👍

@rsanheim
Copy link
Author

Can I take over this work?

Please do, I haven't been able to carve out time to continue it and using turbo-test via guard was always a nice to have for me. I still use turbo-test every day for full build runs and it works great for that as-is.

@Gloglok
Copy link

Gloglok commented Mar 20, 2023

Hey I'm very interested in this feature! Been using this gem on my own for a while and my team would love to use it too, but passes --test-options '--order rand' to parallel_tests.

I haven't contributed to open source before, do you think I could help finish this PR? 😄

@ilyazub
Copy link
Collaborator

ilyazub commented Mar 21, 2023

@rsanheim
Copy link
Author

rsanheim commented Oct 7, 2023

This is very out of date, and maybe has been handled upstream? In any case, closing this out.

@rsanheim rsanheim closed this Oct 7, 2023
@rsanheim rsanheim deleted the pass-thru-rspec-options branch October 7, 2023 01:28
ilyazub added a commit that referenced this pull request Nov 22, 2023
Changes
* Remove the default `seed` value (ref: #33)
* Use exit status from RSpec calls (ref: #20)
ilyazub added a commit that referenced this pull request Nov 22, 2023
Changes
* Remove the default `seed` value (ref: #33)
* Use exit status from RSpec calls (ref: #20)
@ilyazub ilyazub mentioned this pull request Jan 17, 2024
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 this pull request may close these issues.

5 participants