|
2 | 2 | import time
|
3 | 3 | from _thread import start_new_thread
|
4 | 4 |
|
5 |
| -import lock_tests |
| 5 | +RUNNING_ON_CI = True |
| 6 | +try: |
| 7 | + import lock_tests |
| 8 | +except ImportError: |
| 9 | + from test import lock_tests |
| 10 | + RUNNING_ON_CI = False |
6 | 11 | from .. import DynamoLock, FileLock, RedisLock, SocketLock
|
7 | 12 |
|
8 |
| -RUNNING_ON_CI = True |
9 |
| -# try: |
10 |
| -# RUNNING_ON_CI = True |
11 |
| -# except ImportError: |
12 |
| -# RUNNING_ON_CI = False |
13 |
| -# from test import lock_tests, support |
14 |
| - |
15 |
| - |
16 |
| -if True: |
17 |
| - class SocketLockTests(lock_tests.LockTests): |
18 |
| - locktype = staticmethod(SocketLock) |
19 |
| - |
20 |
| - class FileLockTests(lock_tests.LockTests): |
21 |
| - locktype = staticmethod(FileLock) |
22 |
| - |
23 |
| - if not RUNNING_ON_CI: |
24 |
| - class DynamoLockTests(lock_tests.LockTests): |
25 |
| - locktype = staticmethod(DynamoLock) |
26 |
| - |
27 |
| - def tearDown(self): |
28 |
| - for ithread in threading.enumerate(): |
29 |
| - if hasattr(ithread, 'exit_flag'): |
30 |
| - ithread.exit_flag.set() |
31 |
| - ithread.join() |
32 |
| - |
33 |
| - def test_reacquire(self): |
34 |
| - """Copied in because the wait_threads_exit """ |
35 |
| - # Lock needs to be released before re-acquiring. |
36 |
| - lock = self.locktype() |
37 |
| - phase = [] |
38 |
| - |
39 |
| - def f(): |
40 |
| - lock.acquire() |
41 |
| - phase.append(None) |
42 |
| - lock.acquire() |
43 |
| - phase.append(None) |
44 |
| - |
45 |
| - with lock_tests.support.wait_threads_exit(timeout=5): |
46 |
| - start_new_thread(f, ()) |
47 |
| - while len(phase) == 0: |
48 |
| - _wait() |
| 13 | + |
| 14 | +class SocketLockTests(lock_tests.LockTests): |
| 15 | + locktype = staticmethod(SocketLock) |
| 16 | + |
| 17 | +class FileLockTests(lock_tests.LockTests): |
| 18 | + locktype = staticmethod(FileLock) |
| 19 | + |
| 20 | +if not RUNNING_ON_CI: |
| 21 | + class DynamoLockTests(lock_tests.LockTests): |
| 22 | + locktype = staticmethod(DynamoLock) |
| 23 | + |
| 24 | + def tearDown(self): |
| 25 | + for ithread in threading.enumerate(): |
| 26 | + if hasattr(ithread, 'exit_flag'): |
| 27 | + ithread.exit_flag.set() |
| 28 | + ithread.join() |
| 29 | + |
| 30 | + def test_reacquire(self): |
| 31 | + """Copied in because the wait_threads_exit """ |
| 32 | + # Lock needs to be released before re-acquiring. |
| 33 | + lock = self.locktype() |
| 34 | + phase = [] |
| 35 | + |
| 36 | + def f(): |
| 37 | + lock.acquire() |
| 38 | + phase.append(None) |
| 39 | + lock.acquire() |
| 40 | + phase.append(None) |
| 41 | + |
| 42 | + with lock_tests.support.wait_threads_exit(timeout=5): |
| 43 | + start_new_thread(f, ()) |
| 44 | + while len(phase) == 0: |
49 | 45 | _wait()
|
50 |
| - self.assertEqual(len(phase), 1) |
51 |
| - lock.release() |
52 |
| - while len(phase) == 1: |
53 |
| - _wait() |
54 |
| - self.assertEqual(len(phase), 2) |
55 |
| - lock.release() |
56 |
| - |
57 |
| - def test_thread_leak(self): |
58 |
| - pass |
| 46 | + _wait() |
| 47 | + self.assertEqual(len(phase), 1) |
| 48 | + lock.release() |
| 49 | + while len(phase) == 1: |
| 50 | + _wait() |
| 51 | + self.assertEqual(len(phase), 2) |
| 52 | + lock.release() |
| 53 | + |
| 54 | + def test_thread_leak(self): |
| 55 | + pass |
59 | 56 |
|
60 | 57 |
|
61 | 58 | def _wait():
|
|
0 commit comments