From 1211e4951975cb79c6f50f1d14b10b2b31ce75d7 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Wed, 24 Jan 2024 11:59:30 +0000 Subject: [PATCH] Only wait for background tasks on tests that need them --- test/test_helper.rb | 4 ---- test/unit/cluster_test.rb | 4 ++++ test/unit/execution_test.rb | 4 ++++ test/unit/expiry_test.rb | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index e140e5c..3245ca6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 = {}) diff --git a/test/unit/cluster_test.rb b/test/unit/cluster_test.rb index 788d5e2..14fdd9e 100644 --- a/test/unit/cluster_test.rb +++ b/test/unit/cluster_test.rb @@ -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) diff --git a/test/unit/execution_test.rb b/test/unit/execution_test.rb index 246aa88..f8a24b3 100644 --- a/test/unit/execution_test.rb +++ b/test/unit/execution_test.rb @@ -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) diff --git a/test/unit/expiry_test.rb b/test/unit/expiry_test.rb index 127caf7..7bdde3b 100644 --- a/test/unit/expiry_test.rb +++ b/test/unit/expiry_test.rb @@ -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)