mirror of
https://github.com/wassname/cachier.git
synced 2026-09-12 12:10:48 +08:00
Add prints to follow the flow in CI
This commit is contained in:
@@ -134,18 +134,19 @@ class _MongoCore(_BaseCore):
|
||||
def wait_on_entry_calc(self, key):
|
||||
time_spent = 0
|
||||
while True:
|
||||
print("Waiting for Mongo cache...")
|
||||
time.sleep(MONGO_SLEEP_DURATION_IN_SEC)
|
||||
time_spent += MONGO_SLEEP_DURATION_IN_SEC
|
||||
key, entry = self.get_entry_by_key(key)
|
||||
if entry is None:
|
||||
raise RecalculationNeeded()
|
||||
|
||||
if entry is not None:
|
||||
if not entry['being_calculated']:
|
||||
return entry['value']
|
||||
if not entry['being_calculated']:
|
||||
return entry['value']
|
||||
|
||||
if self.wait_for_calc_timeout > 0 and time_spent >= self.wait_for_calc_timeout:
|
||||
raise RecalculationNeeded()
|
||||
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)
|
||||
raise RecalculationNeeded()
|
||||
|
||||
|
||||
def clear_cache(self):
|
||||
|
||||
@@ -177,12 +177,14 @@ def test_mongo_wait_for_calc_timeout_ok():
|
||||
|
||||
@cachier(mongetter=_test_mongetter, stale_after=MONGO_DELTA_LONG, next_time=False, wait_for_calc_timeout=2)
|
||||
def _wait_for_calc_timeout_mongo_slow(arg_1, arg_2):
|
||||
print("_wait_for_calc_timeout_mongo_slow")
|
||||
"""Some function."""
|
||||
sleep(3)
|
||||
return random() + arg_1 + arg_2
|
||||
|
||||
|
||||
def _calls_wait_for_calc_timeout_mongo_slow(res_queue):
|
||||
print("_calls_wait_for_calc_timeout_mongo_slow")
|
||||
res = _wait_for_calc_timeout_mongo_slow(1, 2)
|
||||
res_queue.put(res)
|
||||
|
||||
@@ -190,6 +192,7 @@ def _calls_wait_for_calc_timeout_mongo_slow(res_queue):
|
||||
def test_mongo_wait_for_calc_timeout_slow():
|
||||
"""Testing for calls timing out to be performed twice when needed."""
|
||||
_wait_for_calc_timeout_mongo_slow.clear_cache()
|
||||
print("Cache cleared")
|
||||
res_queue = queue.Queue()
|
||||
thread1 = threading.Thread(
|
||||
target=_calls_wait_for_calc_timeout_mongo_slow, kwargs={'res_queue': res_queue})
|
||||
@@ -198,7 +201,7 @@ def test_mongo_wait_for_calc_timeout_slow():
|
||||
|
||||
thread1.start()
|
||||
thread2.start()
|
||||
sleep(3)
|
||||
sleep(4)
|
||||
thread1.join()
|
||||
thread2.join()
|
||||
assert res_queue.qsize() == 2
|
||||
|
||||
Reference in New Issue
Block a user