Changeset 815066c in trunk


Ignore:
Timestamp:
2023-03-20T19:25:52Z (2 years ago)
Author:
Itamar Turner-Trauring <itamar@…>
Branches:
master
Children:
23b977a
Parents:
cce5d3a
Message:

Just use the utility.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified integration/util.py

    rcce5d3a r815066c  
    431431
    432432
     433def 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
    433458def await_file_contents(path, contents, timeout=15, error_if=None):
    434459    """
     
    556581
    557582
     583@run_in_thread
    558584def await_client_ready(tahoe, timeout=10, liveness=60*2, minimum_number_of_servers=1):
    559585    """
     
    571597    to be true. Otherwise, an exception is raised
    572598    """
    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):
    577599    start = time.time()
    578600    while (time.time() - start) < float(timeout):
     
    627649
    628650
    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 are
    633     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 the
    636     background using Twisted APIs.  The nodes stdout and stderr is read via
    637     Twisted code.  If the reactor doesn't run, reads don't happen, and
    638     eventually the buffers fill up, and the nodes block when they try to flush
    639     logs.
    640 
    641     We can switch to Twisted APIs (treq instead of requests etc.), but
    642     sometimes it's easier or expedient to just have a blocking test.  So this
    643     decorator allows you to run the test in a thread, and the reactor can keep
    644     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 test
    652 
    653651@frozen
    654652class CHK:
Note: See TracChangeset for help on using the changeset viewer.