Skip to content

Commit

Permalink
DEV: Split out multisite tests in bin/turbo_rspec
Browse files Browse the repository at this point in the history
 * A new process is started that just runs the multisite tests
 * The other processes are instructed to exclude the multisite tests
  • Loading branch information
danielwaterworth committed Aug 29, 2019
1 parent 0bf3316 commit 15c02c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
52 changes: 38 additions & 14 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def run

setup_tmp_dir

tests_in_groups.each_with_index do |tests, process_num|
start_subprocess(tests, process_num + 1)
start_multisite_subprocess(@files)

tests_in_groups.each_with_index do |tests, process_id|
start_regular_subprocess(tests, process_id + 1)
end

handle_messages
Expand Down Expand Up @@ -83,49 +85,71 @@ def setup_tmp_dir
FileUtils.mkdir_p('tmp/test-pipes/')
end

def start_subprocess(tests, process_num)
def start_multisite_subprocess(tests)
start_subprocess(
{},
["--tag", "type:multisite"],
tests,
"multisite"
)
end

def start_regular_subprocess(tests, process_id)
start_subprocess(
{ 'TEST_ENV_NUMBER' => process_id.to_s },
["--tag", "~type:multisite"],
tests,
process_id
)
end

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

begin
File.mkfifo("tmp/test-pipes/subprocess-#{process_num}")
File.mkfifo(tmp_filename)
rescue Errno::EEXIST
end

env = { 'TEST_ENV_NUMBER' => process_num.to_s }
env['RSPEC_SILENCE_FILTER_ANNOUNCEMENTS'] = '1'

command = [
"bundle", "exec", "rspec",
"-f", "TurboTests::JsonRowsFormatter",
"-o", "tmp/test-pipes/subprocess-#{process_num}",
*extra_args,
"--format", "TurboTests::JsonRowsFormatter",
"--out", tmp_filename,
*tests
]

if @verbose
command_str = [
env.map { |k, v| "#{k}=#{v}" }.join(' '),
command.join(' ')
].join(' ')
].select { |x| x.size > 0 }.join(' ')

STDERR.puts "Process #{process_num}: #{command_str}"
STDERR.puts "Process #{process_id}: #{command_str}"
end

_stdin, stdout, stderr, _wait_thr = Open3.popen3(env, *command)

@threads <<
Thread.new do
File.open("tmp/test-pipes/subprocess-#{process_num}") do |fd|
File.open(tmp_filename) do |fd|
fd.each_line do |line|
message = JSON.parse(line)
message = message.symbolize_keys
message[:process_num] = process_num
message[:process_id] = process_id
@messages << message
end
end

@messages << { type: 'exit', process_num: process_num }
@messages << { type: 'exit', process_id: process_id }
end

@threads << start_copy_thread(stdout, STDOUT)
Expand Down Expand Up @@ -167,7 +191,7 @@ def handle_messages
when 'close'
when 'exit'
exited += 1
if exited == @num_processes
if exited == @num_processes + 1
break
end
else
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def fab!(name, &blk)

RSpec.configure do |config|
config.fail_fast = ENV['RSPEC_FAIL_FAST'] == "1"
config.silence_filter_announcements = ENV['RSPEC_SILENCE_FILTER_ANNOUNCEMENTS'] == "1"
config.include Helpers
config.include MessageBus
config.include RSpecHtmlMatchers
Expand Down

0 comments on commit 15c02c0

Please sign in to comment.