From 84883a923c84f010d2ed4255a8d868e996caaaf6 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Thu, 29 Feb 2024 08:56:19 -0500 Subject: [PATCH] fix sporadic thread_safety test failure For this test, the spawned thread was ending after the main block was running When the main block quit, it undefined the method on the class. The threaded class kept calling the method (now undefined) and threw an exception because the method was no longer defined. solution is to wait for the thread to finish before exiting and undefining the method --- spec/core_ext/module/cache_with_timeout_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/core_ext/module/cache_with_timeout_spec.rb b/spec/core_ext/module/cache_with_timeout_spec.rb index 7b79a75..98f46e8 100644 --- a/spec/core_ext/module/cache_with_timeout_spec.rb +++ b/spec/core_ext/module/cache_with_timeout_spec.rb @@ -163,7 +163,7 @@ # clears the current value, the other thread could get nil. test_class.cache_with_timeout(:thread_safety) { 2 } - Thread.new do + t = Thread.new do 10000.times do test_class.thread_safety(true) end @@ -172,6 +172,7 @@ 10000.times do expect(test_class.thread_safety).to eq(2) end + t.join end end end