Skip to content

Commit

Permalink
Don't sleep when replaying recorded data
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Nov 4, 2016
1 parent a7d21ba commit 97344ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.auth = create_auth()
self.api = API(self.auth)
self.api.retry_count = 2
self.api.retry_delay = 5
self.api.retry_delay = 0 if use_replay else 5


def create_auth():
Expand Down
13 changes: 9 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import random
import shutil
from time import sleep
import time
import os
from ast import literal_eval

Expand Down Expand Up @@ -440,7 +440,7 @@ def testcachedresult(self):


class TweepyCacheTests(unittest.TestCase):
timeout = 2.0
timeout = 0.5
memcache_servers = ['127.0.0.1:11211'] # must be running for test to pass

def _run_tests(self, do_cleanup=True):
Expand All @@ -450,14 +450,14 @@ def _run_tests(self, do_cleanup=True):
'Stored value does not match retrieved value')

# test timeout
sleep(self.timeout)
sleep(self.timeout, True)
self.assertEqual(self.cache.get('testkey'), None,
'Cache entry should have expired')

# test cleanup
if do_cleanup:
self.cache.store('testkey', 'testvalue')
sleep(self.timeout)
sleep(self.timeout, True)
self.cache.cleanup()
self.assertEqual(self.cache.count(), 0, 'Cache cleanup failed')

Expand All @@ -484,6 +484,11 @@ def testfilecache(self):
if os.path.exists('cache_test_dir'):
shutil.rmtree('cache_test_dir')

old_sleep = time.sleep

def sleep(t, override=False):
if not use_replay or override:
old_sleep(t)

if __name__ == '__main__':
unittest.main()

0 comments on commit 97344ad

Please sign in to comment.