Changeset 815066c in trunk
- Timestamp:
- 2023-03-20T19:25:52Z (2 years ago)
- Branches:
- master
- Children:
- 23b977a
- Parents:
- cce5d3a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified integration/util.py ¶
rcce5d3a r815066c 431 431 432 432 433 def run_in_thread(f): 434 """Decorator for integration tests that runs code in a thread. 435 436 Because we're using pytest_twisted, tests that rely on the reactor are 437 expected to return a Deferred and use async APIs so the reactor can run. 438 439 In the case of the integration test suite, it launches nodes in the 440 background using Twisted APIs. The nodes stdout and stderr is read via 441 Twisted code. If the reactor doesn't run, reads don't happen, and 442 eventually the buffers fill up, and the nodes block when they try to flush 443 logs. 444 445 We can switch to Twisted APIs (treq instead of requests etc.), but 446 sometimes it's easier or expedient to just have a blocking test. So this 447 decorator allows you to run the test in a thread, and the reactor can keep 448 running in the main thread. 449 450 See https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3597 for tracking bug. 451 """ 452 @wraps(f) 453 def test(*args, **kwargs): 454 return deferToThread(lambda: f(*args, **kwargs)) 455 return test 456 457 433 458 def await_file_contents(path, contents, timeout=15, error_if=None): 434 459 """ … … 556 581 557 582 583 @run_in_thread 558 584 def await_client_ready(tahoe, timeout=10, liveness=60*2, minimum_number_of_servers=1): 559 585 """ … … 571 597 to be true. Otherwise, an exception is raised 572 598 """ 573 return deferToThread(_await_client_ready_blocking, tahoe, timeout, liveness, minimum_number_of_servers)574 575 576 def _await_client_ready_blocking(tahoe, timeout, liveness, minimum_number_of_servers):577 599 start = time.time() 578 600 while (time.time() - start) < float(timeout): … … 627 649 628 650 629 def run_in_thread(f):630 """Decorator for integration tests that runs code in a thread.631 632 Because we're using pytest_twisted, tests that rely on the reactor are633 expected to return a Deferred and use async APIs so the reactor can run.634 635 In the case of the integration test suite, it launches nodes in the636 background using Twisted APIs. The nodes stdout and stderr is read via637 Twisted code. If the reactor doesn't run, reads don't happen, and638 eventually the buffers fill up, and the nodes block when they try to flush639 logs.640 641 We can switch to Twisted APIs (treq instead of requests etc.), but642 sometimes it's easier or expedient to just have a blocking test. So this643 decorator allows you to run the test in a thread, and the reactor can keep644 running in the main thread.645 646 See https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3597 for tracking bug.647 """648 @wraps(f)649 def test(*args, **kwargs):650 return deferToThread(lambda: f(*args, **kwargs))651 return test652 653 651 @frozen 654 652 class CHK:
Note: See TracChangeset
for help on using the changeset viewer.