diff options
| author | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-01-03 12:10:43 +0100 |
|---|---|---|
| committer | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-01-07 20:29:03 +0100 |
| commit | bd1ee67552b1fbbdacda9116b3d9ef6e07edd82d (patch) | |
| tree | 0e7824bb272cc253098904697a58770f5a18f8ba /sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py | |
| parent | 8c9ad6eacc66065130b226ba486749d0eae48226 (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>
Diffstat (limited to 'sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py')
| -rw-r--r-- | sources/pyside6/tests/QtAsyncio/qasyncio_test_queues.py | 14 |
1 files changed, 8 insertions, 6 deletions
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: |
