Skip to content

Commit

Permalink
Run CachedOrderedDict expiration tests in parallel
Browse files Browse the repository at this point in the history
Do your part to keep unit test suite runs fast.  :-)
  • Loading branch information
brainix committed Dec 2, 2020
1 parent 333f05f commit c16ef6c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


import collections
import concurrent.futures
import random
import time
from unittest import mock
Expand Down Expand Up @@ -569,13 +570,25 @@ def test_no_keys(self):
assert cache.misses() == set()

def test_expiration(self):
futures = []
with concurrent.futures.ThreadPoolExecutor() as executor:
for test_method in {
self._test_expiration,
self._test_no_expiration,
}:
future = executor.submit(test_method)
futures.append(future)
for future in futures:
future.result()

def _test_expiration(self):
assert self.redis.ttl(self._KEY_EXPIRATION) == _DEFAULT_TIMEOUT
time.sleep(1)
assert self.redis.ttl(self._KEY_EXPIRATION) == _DEFAULT_TIMEOUT - 1
self.cache_expiration['hit4'] = 'value4'
assert self.redis.ttl(self._KEY_EXPIRATION) == _DEFAULT_TIMEOUT

def test_no_expiration(self):
def _test_no_expiration(self):
assert self.redis.ttl(self._KEY_NO_EXPIRATION) == -1
time.sleep(1)
assert self.redis.ttl(self._KEY_NO_EXPIRATION) == -1
Expand Down

0 comments on commit c16ef6c

Please sign in to comment.