Skip to content

Commit

Permalink
Merge pull request #27 from basecamp/faster-tests
Browse files Browse the repository at this point in the history
Reduce pauses for faster tests
  • Loading branch information
djmb authored Oct 12, 2023
2 parents 0da33d5 + 943fe72 commit b7b960b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions test/integration/jobs_lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JobsLifecycleTest < ActiveSupport::TestCase
@scheduler.start(mode: :async)
@worker.start(mode: :async)

wait_for_jobs_to_finish_for(5.seconds)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_equal [ "hey", "ho" ], JobBuffer.values.sort
end
Expand All @@ -44,7 +44,7 @@ class JobsLifecycleTest < ActiveSupport::TestCase

travel_to 5.days.from_now

wait_for_jobs_to_finish_for(5.seconds)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_equal 2, JobBuffer.size
assert_equal "I'm scheduled later", JobBuffer.last_value
Expand Down
42 changes: 21 additions & 21 deletions test/integration/processes_lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ProcessLifecycleTest < ActiveSupport::TestCase
setup do
@pid = run_supervisor_as_fork

wait_for_registered_processes(3, timeout: 1.second)
wait_for_registered_processes(3, timeout: 0.1.second)
assert_registered_processes_for(:background, :default)
end

Expand All @@ -20,7 +20,7 @@ class ProcessLifecycleTest < ActiveSupport::TestCase
6.times.map { |i| enqueue_store_result_job("job_#{i}") }
6.times.map { |i| enqueue_store_result_job("job_#{i}", :default) }

wait_for_jobs_to_finish_for(5.seconds)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_equal 12, JobResult.count
6.times { |i| assert_completed_job_results("job_#{i}", :background) }
Expand All @@ -32,10 +32,10 @@ class ProcessLifecycleTest < ActiveSupport::TestCase

test "kill supervisor while there are jobs in-flight" do
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: 2.seconds)
pause = enqueue_store_result_job("pause", pause: 0.2.seconds)

signal_process(@pid, :KILL, wait: 1.second)
wait_for_jobs_to_finish_for(5.seconds)
signal_process(@pid, :KILL, wait: 0.1.second)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_not process_exists?(@pid)

Expand All @@ -60,10 +60,10 @@ class ProcessLifecycleTest < ActiveSupport::TestCase

test "quit supervisor while there are jobs in-flight" do
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: 2.seconds)
pause = enqueue_store_result_job("pause", pause: 1.seconds)

signal_process(@pid, :QUIT, wait: 1.second)
wait_for_jobs_to_finish_for(5.seconds)
signal_process(@pid, :QUIT, wait: 0.5.second)
wait_for_jobs_to_finish_for(2.5.seconds)

assert_not process_exists?(@pid)

Expand All @@ -81,10 +81,10 @@ class ProcessLifecycleTest < ActiveSupport::TestCase

test "term supervisor while there are jobs in-flight" do
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: 2.seconds)
pause = enqueue_store_result_job("pause", pause: 0.2.seconds)

signal_process(@pid, :TERM, wait: 1.second)
wait_for_jobs_to_finish_for(5.seconds)
signal_process(@pid, :TERM, wait: 0.1.second)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_completed_job_results("no pause")
assert_completed_job_results("pause")
Expand All @@ -97,10 +97,10 @@ class ProcessLifecycleTest < ActiveSupport::TestCase

test "int supervisor while there are jobs in-flight" do
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: 2.seconds)
pause = enqueue_store_result_job("pause", pause: 0.2.seconds)

signal_process(@pid, :INT, wait: 1.second)
wait_for_jobs_to_finish_for(5.seconds)
signal_process(@pid, :INT, wait: 0.1.second)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_completed_job_results("no pause")
assert_completed_job_results("pause")
Expand All @@ -113,10 +113,10 @@ class ProcessLifecycleTest < ActiveSupport::TestCase

test "term supervisor exceeding timeout while there are jobs in-flight" do
no_pause = enqueue_store_result_job("no pause")
pause = enqueue_store_result_job("pause", pause: SolidQueue.shutdown_timeout + 1.second)
pause = enqueue_store_result_job("pause", pause: SolidQueue.shutdown_timeout + 0.1.second)

signal_process(@pid, :TERM, wait: 1.second)
wait_for_jobs_to_finish_for(SolidQueue.shutdown_timeout + 1.second)
signal_process(@pid, :TERM, wait: 0.1.second)
wait_for_jobs_to_finish_for(SolidQueue.shutdown_timeout + 0.1.second)

assert_completed_job_results("no pause")
assert_job_status(no_pause, :finished)
Expand All @@ -134,12 +134,12 @@ class ProcessLifecycleTest < ActiveSupport::TestCase
enqueue_store_result_job("no error", :background, 2)
enqueue_store_result_job("no error", :default, 2)
error1 = enqueue_store_result_job("error", :background, 1, exception: RuntimeError)
enqueue_store_result_job("no error", :background, 1, pause: 0.3)
error2 = enqueue_store_result_job("error", :background, 1, exception: RuntimeError, pause: 0.5)
enqueue_store_result_job("no error", :default, 2, pause: 0.1)
enqueue_store_result_job("no error", :background, 1, pause: 0.03)
error2 = enqueue_store_result_job("error", :background, 1, exception: RuntimeError, pause: 0.05)
enqueue_store_result_job("no error", :default, 2, pause: 0.01)
error3 = enqueue_store_result_job("error", :default, 1, exception: RuntimeError)

wait_for_jobs_to_finish_for(5.seconds)
wait_for_jobs_to_finish_for(0.5.seconds)

assert_completed_job_results("no error", :background, 3)
assert_completed_job_results("no error", :default, 4)
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ActiveSupport::TestCase
end

private
def wait_for_jobs_to_finish_for(timeout = 10.seconds)
def wait_for_jobs_to_finish_for(timeout = 1.second)
Timeout.timeout(timeout) do
while SolidQueue::Job.where(finished_at: nil).any? do
sleep 0.25
Expand All @@ -41,7 +41,7 @@ def run_supervisor_as_fork(**options)
end
end

def wait_for_registered_processes(count, timeout: 10.seconds)
def wait_for_registered_processes(count, timeout: 1.second)
Timeout.timeout(timeout) do
while SolidQueue::Process.count < count do
sleep 0.25
Expand Down
2 changes: 1 addition & 1 deletion test/unit/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WorkerTest < ActiveSupport::TestCase

test "claim and process more enqueued jobs than the pool size allows to process at once" do
5.times do |i|
StoreResultJob.perform_later(:paused, pause: 1.second)
StoreResultJob.perform_later(:paused, pause: 0.1.second)
end

3.times do |i|
Expand Down

0 comments on commit b7b960b

Please sign in to comment.