diff --git a/cachier/mongo_core.py b/cachier/mongo_core.py index f481823..b1c986f 100644 --- a/cachier/mongo_core.py +++ b/cachier/mongo_core.py @@ -144,8 +144,9 @@ class _MongoCore(_BaseCore): if not entry['being_calculated']: return entry['value'] + print("Got an entry. It is being calculated. Do we wait?", time_spent, self.wait_for_calc_timeout, time_spent >= self.wait_for_calc_timeout) if self.wait_for_calc_timeout > 0 and time_spent >= self.wait_for_calc_timeout: - print("Got an entry. Is not valid. Force recomputation.", time_spent, self.wait_for_calc_timeout, time_spent >= self.wait_for_calc_timeout) + print("Tired of waiting. RecalculationNeeded.", time_spent, self.wait_for_calc_timeout, time_spent >= self.wait_for_calc_timeout) raise RecalculationNeeded() diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index 726c61e..7895daa 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -201,15 +201,17 @@ def test_mongo_wait_for_calc_timeout_slow(): thread1.start() thread2.start() + sleep(1) + res3 = _wait_for_calc_timeout_mongo_slow(1, 2) sleep(4) thread1.join() - thread2.join() + thread2.join() assert res_queue.qsize() == 2 res1 = res_queue.get() res2 = res_queue.get() assert res1 != res2 # Timeout kicked in. Two calls were done - res3 = _wait_for_calc_timeout_mongo_slow(1, 2) - assert res2 == res3 or res1 == res3 # One of the cached values is returned + res4 = _wait_for_calc_timeout_mongo_slow(1, 2) + assert res1 == res4 or res2 == res4 or res3 == res4 # One of the cached values is returned class _BadMongoCollection: