Fix Noparallel test on slower machines

This commit is contained in:
shortcutme 2019-03-16 03:02:59 +01:00
parent f0b53c4cbb
commit ea638dd0e0
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -92,12 +92,12 @@ class TestNoparallel:
obj1 = ExampleClass() obj1 = ExampleClass()
threads = [] threads = []
for i in range(10000): for i in range(1000):
thread = gevent.spawn(obj1.countQueue, num=5) thread = gevent.spawn(obj1.countQueue, num=5)
threads.append(thread) threads.append(thread)
gevent.joinall(threads) gevent.joinall(threads)
assert obj1.counted == 5 * 2 # Only called twice assert obj1.counted == 5 * 2 # Only called twice (no multi-queue allowed)
def testIgnoreClass(self): def testIgnoreClass(self):
obj1 = ExampleClass() obj1 = ExampleClass()
@ -111,10 +111,12 @@ class TestNoparallel:
gevent.spawn(obj2.countQueue) gevent.spawn(obj2.countQueue)
] ]
s = time.time() s = time.time()
time.sleep(0)
gevent.joinall(threads) gevent.joinall(threads)
# Queue limited to 2 calls (very call takes counts to 5 and takes 0.05 sec) # Queue limited to 2 calls (every call takes counts to 5 and takes 0.05 sec)
assert obj1.counted + obj2.counted == 10 assert obj1.counted == 10
assert obj2.counted == 0
taken = time.time() - s taken = time.time() - s
assert 1.1 > taken >= 1.0 # 2 * 0.5s count = ~1s assert 1.2 > taken >= 1.0 # 2 * 0.5s count = ~1s