Skip to content

Commit

Permalink
test: Add helper to temporarily suppress stdout
Browse files Browse the repository at this point in the history
This makes up testing output much cleaner.

Part of #1
  • Loading branch information
agis committed Jul 22, 2020
1 parent 87de277 commit 4d9be02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 10 additions & 1 deletion test/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ def start_worker(build_id:, worker_id: rand_id, suite:)
Process.spawn(
"#{EXEC_CMD} -w #{worker_id} -b #{build_id}",
chdir: suite_path(suite),
out: (ENV["RSPECQ_DEBUG"] ? :out : "/dev/null"),
out: (ENV["RSPECQ_DEBUG"] ? :out : File::NULL),
)
end

# Supresses stdout of the code provided in the block
def silent
orig = $stdout.clone
$stdout.reopen(File::NULL, 'w')
yield
ensure
$stdout.reopen(orig)
end
end

# To be subclassed from all test cases.
Expand Down
14 changes: 7 additions & 7 deletions test/test_scheduling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class TestScheduling < RSpecQTest
def test_scheduling_with_timings_simple
worker = new_worker("timings")
worker.populate_timings = true
worker.work
silent { worker.work }

assert_queue_well_formed(worker.queue)

worker = new_worker("timings")
# worker.populate_timings is false by default
queue = worker.queue
worker.try_publish_queue!(queue)
silent { worker.try_publish_queue!(queue) }

assert_equal [
"./test/sample_suites/timings/spec/very_slow_spec.rb",
Expand All @@ -25,15 +25,15 @@ def test_scheduling_with_timings_simple
def test_scheduling_with_timings_and_splitting
worker = new_worker("scheduling")
worker.populate_timings = true
worker.work
silent { worker.work }

assert_queue_well_formed(worker.queue)

# 1st run with timings, the slow file will be split
worker = new_worker("scheduling")
worker.populate_timings = true
worker.file_split_threshold = 0.2
worker.work
silent { worker.work }

assert_queue_well_formed(worker.queue)

Expand All @@ -47,7 +47,7 @@ def test_scheduling_with_timings_and_splitting
worker = new_worker("scheduling")
worker.populate_timings = true
worker.file_split_threshold = 0.2
worker.try_publish_queue!(worker.queue)
silent { worker.try_publish_queue!(worker.queue) }

assert_equal [
"./test/sample_suites/scheduling/spec/foo_spec.rb[1:2:1]",
Expand All @@ -59,14 +59,14 @@ def test_scheduling_with_timings_and_splitting
def test_untimed_jobs_scheduled_in_the_middle
worker = new_worker("scheduling_untimed/spec/foo")
worker.populate_timings = true
worker.work
silent { worker.work }

assert_queue_well_formed(worker.queue)
assert worker.queue.build_successful?
refute_empty worker.queue.timings

worker = new_worker("scheduling_untimed")
worker.try_publish_queue!(worker.queue)
silent { worker.try_publish_queue!(worker.queue) }
assert_equal [
"./test/sample_suites/scheduling_untimed/spec/foo/bar_spec.rb",
"./test/sample_suites/scheduling_untimed/spec/foo/foo_spec.rb",
Expand Down

0 comments on commit 4d9be02

Please sign in to comment.