aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2024-01-03 12:10:43 +0100
committerAdrian Herrmann <adrian.herrmann@qt.io>2024-01-07 20:29:03 +0100
commitbd1ee67552b1fbbdacda9116b3d9ef6e07edd82d (patch)
tree0e7824bb272cc253098904697a58770f5a18f8ba
parent8c9ad6eacc66065130b226ba486749d0eae48226 (diff)
QtAsyncio: Shorten test durations
Most QtAsyncio tests are slow because they sleeps. Shorten their durations across the board by using shorter sleeps. E.g., this reduces the duration of the queue test from about 16 seconds to less than 6. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I5072bb71fbe28509427fb92390584ec1a4d1a128 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test.py2
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test_chain.py4
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test_executor.py3
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py14
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test_threadsafe.py2
-rw-r--r--sources/pyside6/tests/QtAsyncio/qasyncio_test_time.py2
6 files changed, 15 insertions, 12 deletions
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test.py
index 953483818..f3c971285 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test.py
@@ -12,7 +12,7 @@ from PySide6.QtAsyncio import QAsyncioEventLoopPolicy
class QAsyncioTestCase(unittest.TestCase):
async def sleep(self, output):
output += "Hello"
- await asyncio.sleep(1)
+ await asyncio.sleep(0.2)
output += "World"
async def gather(self, output):
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test_chain.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test_chain.py
index f45b51a71..a0a949720 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test_chain.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test_chain.py
@@ -22,8 +22,8 @@ class QAsyncioTestCaseChain(unittest.TestCase):
return result
async def chain(self, output, n):
- link1 = await self.link(output, n, 1)
- link2 = await self.link(output, n, 2)
+ link1 = await self.link(output, n, 0.2)
+ link2 = await self.link(output, n, 0.5)
output += f"chain {n}: {link1} -> {link2} "
async def gather(self, output, *args):
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test_executor.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test_executor.py
index f343aa73b..25e680b39 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test_executor.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test_executor.py
@@ -27,7 +27,8 @@ class QAsyncioTestCaseExecutor(unittest.TestCase):
async def run_asyncio_executor(self):
main_thread = QThread.currentThread()
with ThreadPoolExecutor(max_workers=2) as executor:
- result = await asyncio.get_running_loop().run_in_executor(executor, self.blocking_function)
+ result = await asyncio.get_running_loop().run_in_executor(
+ executor, self.blocking_function)
# Assert that we are back to the main thread.
self.assertEqual(QThread.currentThread(), main_thread)
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py
index 38827b0f7..0bd98c361 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py
@@ -14,24 +14,26 @@ from PySide6.QtAsyncio import QAsyncioEventLoopPolicy
class QAsyncioTestCaseQueues(unittest.TestCase):
async def produce(self, output, queue):
- for _ in range(random.randint(0, 3)):
- await asyncio.sleep(random.randint(0, 2))
+ for _ in range(random.randint(0, 2)):
+ await asyncio.sleep(random.random())
await queue.put(self.i)
output += f"{self.i} added to queue\n"
self.i += 1
async def consume(self, output, queue):
while True:
- await asyncio.sleep(random.randint(0, 2))
+ await asyncio.sleep(random.random())
i = await queue.get()
output += f"{i} pulled from queue\n"
queue.task_done()
async def main(self, output1, output2, num_producers, num_consumers):
self.i = 0
- queue = asyncio.Queue() # type: asyncio.Queue
- producers = [asyncio.create_task(self.produce(output1, queue)) for _ in range(num_producers)]
- consumers = [asyncio.create_task(self.consume(output2, queue)) for _ in range(num_consumers)]
+ queue = asyncio.Queue()
+ producers = [
+ asyncio.create_task(self.produce(output1, queue)) for _ in range(num_producers)]
+ consumers = [
+ asyncio.create_task(self.consume(output2, queue)) for _ in range(num_consumers)]
await asyncio.gather(*producers)
await queue.join()
for consumer in consumers:
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test_threadsafe.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test_threadsafe.py
index 8a7eaf2ce..5b52db239 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test_threadsafe.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test_threadsafe.py
@@ -36,7 +36,7 @@ class QAsyncioTestCaseThreadsafe(unittest.TestCase):
task = asyncio.create_task(self.loop_event.wait())
# The timeout is necessary because the loop will hang for the non-threadsafe case.
- done, pending = await asyncio.wait([task], timeout=3)
+ done, pending = await asyncio.wait([task], timeout=2)
thread.join()
diff --git a/sources/pyside6/tests/QtAsyncio/qasyncio_test_time.py b/sources/pyside6/tests/QtAsyncio/qasyncio_test_time.py
index 60ec2f064..07a126644 100644
--- a/sources/pyside6/tests/QtAsyncio/qasyncio_test_time.py
+++ b/sources/pyside6/tests/QtAsyncio/qasyncio_test_time.py
@@ -33,7 +33,7 @@ class QAsyncioTestCaseTime(unittest.TestCase):
asyncio.set_event_loop_policy(QAsyncioEventLoopPolicy())
loop = asyncio.new_event_loop()
- end_time = loop.time() + 5.0
+ end_time = loop.time() + 3.0
loop.call_soon(self.display_date, end_time, loop)
try: