Skip to content

Commit

Permalink
Only wait for background tasks on tests that need them
Browse files Browse the repository at this point in the history
  • Loading branch information
djmb committed Jan 24, 2024
1 parent c5f1f3b commit 1211e49
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 0 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class ActiveSupport::TestCase
SolidCache::Entry.delete_all
end
end

teardown do
wait_for_background_tasks(@cache) if @cache
end
end

def lookup_store(options = {})
Expand Down
4 changes: 4 additions & 0 deletions test/unit/cluster_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ClusterTest < ActiveSupport::TestCase
@secondary_cache = lookup_store(expires_in: 60, cluster: secondary_cluster)
end

teardown do
wait_for_background_tasks(@cache) if @cache
end

test "writes to both clusters" do
@cache.write("foo", 1)
wait_for_background_tasks(@cache)
Expand Down
4 changes: 4 additions & 0 deletions test/unit/execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class SolidCache::ExecutionTest < ActiveSupport::TestCase
@cache = lookup_store(expiry_batch_size: 2, shards: nil)
end

teardown do
wait_for_background_tasks(@cache) if @cache
end

def test_async_errors_are_reported
error_subscriber = ErrorSubscriber.new
Rails.error.subscribe(error_subscriber)
Expand Down
4 changes: 4 additions & 0 deletions test/unit/expiry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class SolidCache::ExpiryTest < ActiveSupport::TestCase
@namespace = "test-#{SecureRandom.hex}"
end

teardown do
wait_for_background_tasks(@cache) if @cache
end

[ :thread, :job ].each do |expiry_method|
test "expires old records (#{expiry_method})" do
SolidCache::Cluster.any_instance.stubs(:rand).returns(0)
Expand Down

0 comments on commit 1211e49

Please sign in to comment.