Fix noparallel test on slow cpu

This commit is contained in:
shortcutme 2019-01-20 19:07:48 +01:00
parent 44dc3035a5
commit 9e5be7ffcf
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -3,6 +3,7 @@ import time
import util import util
import gevent import gevent
class ExampleClass(object): class ExampleClass(object):
def __init__(self): def __init__(self):
self.counted = 0 self.counted = 0
@ -17,7 +18,7 @@ class ExampleClass(object):
@util.Noparallel(queue=True, ignore_class=True) @util.Noparallel(queue=True, ignore_class=True)
def countQueue(self, num=5): def countQueue(self, num=5):
for i in range(1, num + 1): for i in range(1, num + 1):
time.sleep(0.01) time.sleep(0.1)
self.counted += 1 self.counted += 1
return "counted:%s" % i return "counted:%s" % i
@ -72,24 +73,21 @@ class TestNoparallel:
gevent.spawn(obj1.countQueue, num=10) gevent.spawn(obj1.countQueue, num=10)
gevent.spawn(obj1.countQueue, num=10) gevent.spawn(obj1.countQueue, num=10)
time.sleep(0.3) time.sleep(3.0)
assert obj1.counted == 20 # No multi-queue supported assert obj1.counted == 20 # No multi-queue supported
obj2 = ExampleClass() obj2 = ExampleClass()
gevent.spawn(obj2.countQueue, num=10) gevent.spawn(obj2.countQueue, num=10)
gevent.spawn(obj2.countQueue, num=10) gevent.spawn(obj2.countQueue, num=10)
time.sleep(0.15) # Call 1 finished, call 2 still working time.sleep(1.5) # Call 1 finished, call 2 still working
assert 10 < obj2.counted < 20 assert 10 < obj2.counted < 20
gevent.spawn(obj2.countQueue, num=10) gevent.spawn(obj2.countQueue, num=10)
time.sleep(0.20) time.sleep(2.0)
assert obj2.counted == 30 assert obj2.counted == 30
def testQueueOverload(self): def testQueueOverload(self):
obj1 = ExampleClass() obj1 = ExampleClass()
@ -119,4 +117,4 @@ class TestNoparallel:
assert obj1.counted + obj2.counted == 10 assert obj1.counted + obj2.counted == 10
taken = time.time() - s taken = time.time() - s
assert 0.12 > taken >= 0.1 # 2 * 0.05s count = ~0.1s assert 1.1 > taken >= 1.0 # 2 * 0.5s count = ~1s