|
| 1 | +import warnings |
| 2 | + |
| 3 | +from arango.exceptions import QueueBoundedExecutorError |
| 4 | + |
| 5 | + |
| 6 | +def flood_with_requests(bounded_db, async_db): |
| 7 | + """ |
| 8 | + Flood the database with requests. |
| 9 | + It is impossible to predict what the last recorded queue time will be. |
| 10 | + We can only try and make it as large as possible. However, if the system |
| 11 | + is fast enough, it may still be 0. |
| 12 | + """ |
| 13 | + for _ in range(3): |
| 14 | + for _ in range(500): |
| 15 | + async_db.aql.execute("RETURN SLEEP(0.5)", count=True) |
| 16 | + for _ in range(3): |
| 17 | + bounded_db.aql.execute("RETURN SLEEP(0.5)", count=True) |
| 18 | + if bounded_db.last_queue_time >= 0: |
| 19 | + break |
| 20 | + |
| 21 | + |
| 22 | +def test_queue_bounded(db): |
| 23 | + bounded_db = db.begin_queue_bounded_execution(100) |
| 24 | + async_db = db.begin_async_execution(return_result=True) |
| 25 | + |
| 26 | + flood_with_requests(bounded_db, async_db) |
| 27 | + assert bounded_db.last_queue_time >= 0 |
| 28 | + |
| 29 | + # We can only emit a warning here. The test will still pass. |
| 30 | + if bounded_db.last_queue_time == 0: |
| 31 | + warnings.warn("last_queue_time is 0, test may be unreliable") |
| 32 | + |
| 33 | + bounded_db.adjust_max_queue_time(0.0001) |
| 34 | + try: |
| 35 | + flood_with_requests(bounded_db, async_db) |
| 36 | + assert bounded_db.last_queue_time >= 0 |
| 37 | + except QueueBoundedExecutorError as e: |
| 38 | + assert e.http_code == 412 |
| 39 | + assert e.error_code == 21004 |
| 40 | + else: |
| 41 | + warnings.warn( |
| 42 | + f"last queue time is {bounded_db.last_queue_time}, test may be unreliable" |
| 43 | + ) |
0 commit comments