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

Cleanup temp directory on completion #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "json"
require "parallel_tests/rspec/runner"
require "tmpdir"

require_relative "../utils/hash_extension"

Expand Down Expand Up @@ -84,8 +85,6 @@ def run
**group_opts
)

setup_tmp_dir

subprocess_opts = {
record_runtime: use_runtime_info
}
Expand All @@ -94,50 +93,48 @@ def run

@reporter.seed_notification(@seed, @seed_used)

wait_threads = tests_in_groups.map.with_index do |tests, process_id|
start_regular_subprocess(tests, process_id + 1, **subprocess_opts)
end
setup_tmp_dir do |dir|
wait_threads = tests_in_groups.map.with_index do |tests, process_id|
start_regular_subprocess(tests, process_id + 1, dir, **subprocess_opts)
end

handle_messages
handle_messages

@reporter.finish
@reporter.finish

@reporter.seed_notification(@seed, @seed_used)
@reporter.seed_notification(@seed, @seed_used)

@threads.each(&:join)
@threads.each(&:join)
end

@reporter.failed_examples.empty? && wait_threads.map(&:value).all?(&:success?)
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait_threads are not defined now.

$ bundle exec turbo_tests
Using recorded test runtime
3 processes for 3 specs, ~ 1 specs per process

Randomized with seed 35942

.bundler: failed to load command: turbo_tests (~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests)
~/Workspace/turbo_tests/lib/turbo_tests/runner.rb:110:in `run': undefined local variable or method `wait_threads' for #<TurboTests::Runner:0x00000000015fd588> (NameError)
	from ~/Workspace/turbo_tests/lib/turbo_tests/runner.rb:43:in `run'
	from ~/Workspace/turbo_tests/lib/turbo_tests/cli.rb:101:in `run'
	from ~/Workspace/turbo_tests/bin/turbo_tests:11:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:23:in `load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:23:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:23:in `run'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:492:in `exec'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:34:in `dispatch'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:28:in `start'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/exe/bundle:37:in `block in <top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/exe/bundle:29:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/bin/bundle:23:in `load'
	from ~/.rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
..bundler: failed to load command: turbo_tests (~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests)
~/Workspace/turbo_tests/lib/turbo_tests/runner.rb:110:in `run': undefined local variable or method `wait_threads' for #<TurboTests::Runner:0x00000000023c1548> (NameError)
	from ~/Workspace/turbo_tests/lib/turbo_tests/runner.rb:43:in `run'
	from ~/Workspace/turbo_tests/lib/turbo_tests/cli.rb:101:in `run'
	from ~/Workspace/turbo_tests/bin/turbo_tests:11:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:23:in `load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bin/turbo_tests:23:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:23:in `run'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:492:in `exec'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:34:in `dispatch'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/cli.rb:28:in `start'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/exe/bundle:37:in `block in <top (required)>'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from ~/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bundler-2.4.22/exe/bundle:29:in `<top (required)>'
	from ~/.rbenv/versions/2.7.2/bin/bundle:23:in `load'
	from ~/.rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
F..

Failures:

  1) TurboTests::CLI pending exceptions reports
     Failure/Error: expect($?.exitstatus).to eql(0)
     
       expected: 0
            got: 1
     
       (compared using eql?)
     # ./spec/cli_spec.rb:44:in `block (3 levels) in <top (required)>'

Finished in 3.33 seconds (files took 3.12 seconds to load)
6 examples, 1 failure, 1 error occurred outside of examples

Failed examples:

rspec ./spec/cli_spec.rb:43 # TurboTests::CLI pending exceptions reports


Randomized with seed 35942

end

private

def setup_tmp_dir
begin
FileUtils.rm_r("tmp/test-pipes")
rescue Errno::ENOENT
end

FileUtils.mkdir_p("tmp/test-pipes/")
def setup_tmp_dir(&block)
Dir.mktmpdir("turbo_tests-pipes", &block)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's follow ParallelTests's convention of using ./tmp folder.

Suggested change
Dir.mktmpdir("turbo_tests-pipes", &block)
Dir.mktmpdir("turbo_tests-pipes", "tmp", &block)
Dir.mktmpdir("turbo_tests-pipes", "tmp") { |tmp| puts tmp }
# tmp/turbo_tests-pipes20240117-61561-5k7jqw
# nil

end

def start_regular_subprocess(tests, process_id, **opts)
def start_regular_subprocess(tests, process_id, tmpdir, **opts)
start_subprocess(
{"TEST_ENV_NUMBER" => process_id.to_s},
@tags.map { |tag| "--tag=#{tag}" },
tests,
process_id,
tmpdir,
**opts
)
end

def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
def start_subprocess(env, extra_args, tests, process_id, tmpdir, record_runtime:)
if tests.empty?
@messages << {
type: "exit",
process_id: process_id
}
else
tmp_filename = "tmp/test-pipes/subprocess-#{process_id}"
tmp_filename = File.join(tmpdir, "subprocess-#{process_id}")

begin
File.mkfifo(tmp_filename)
Expand Down