Skip to content

Commit

Permalink
Ensure the thread variables are reset when exiting the block
Browse files Browse the repository at this point in the history
  • Loading branch information
Stivaros committed Jun 11, 2024
1 parent 4a07e6a commit 6faac3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/identity_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def with_deferred_parent_expiration

Thread.current[:deferred_parent_expiration] = nil
Thread.current[:parent_records_for_cache_expiry].each(&:expire_primary_index)
ensure
Thread.current[:deferred_parent_expiration] = nil
Thread.current[:parent_records_for_cache_expiry].clear
end

def with_fetch_read_only_records(value = true)
Expand Down
6 changes: 0 additions & 6 deletions test/index_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ def test_with_deferred_parent_expiration
assert_operator(@memcached_spy.calls.count, :>, 0)
assert_equal(expected_item_expiration_count, item_expiration_count)
assert_equal(expected_associated_record_expiration_count, associated_record_expiration_count)
ensure
Thread.current[:deferred_parent_expiration] = nil
end

def test_double_nested_deferred_parent_expiration
Expand All @@ -215,8 +213,6 @@ def test_double_nested_deferred_parent_expiration
end

assert_equal(0, @memcached_spy.calls.count)
ensure
Thread.current[:deferred_parent_expiration] = nil
end

def test_deep_association_with_deferred_parent_expiration
Expand Down Expand Up @@ -254,8 +250,6 @@ def test_deep_association_with_deferred_parent_expiration
assert_equal(expected_item_expiration_count, item_expiration_count)
assert_equal(expected_associated_record_expiration_count, associated_record_expiration_count)
assert_equal(expected_deeply_associated_record_expiration_count, deeply_associated_record_expiration_count)
ensure
Thread.current[:deferred_parent_expiration] = nil
end

private
Expand Down

0 comments on commit 6faac3f

Please sign in to comment.