Skip to main content

Automation Mojo Waiting Module

Project description

Automation Mojo Waiting Module - mojo-waiting

This package provides support for enhanced context based waiting. This module will greatly enhance the information presented when a wait timeout occurs. Wait contexts are particularly useful for distributed automation. Distributed automation scenarios required lots of wait loops in order wait for the effects of an effect to distributed throughout the distributed system.

The waiting code patterns used are designed to present the best results in test stacktraces presented when a wait fails. This makes the mojo.waiting module perfect for use with test frameworks such as pytest and testplus that show code context in the error report stack traces.

Another important aspect of the mojo.waiting module is that it uses datetime timestamps and timespan for lengths of time so timeouts in error reporting are easier to interpret.

Traceback (most recent call last):
File "/home/myron/repos/mojo.waiting/source/tests/test_wait_for_it.py", line 97, in test_basic_wait_for_it_timeout
    future.result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
File "/home/myron/repos/mojo.waiting/source/tests/test_wait_for_it.py", line 88, in wait_task
    ctxwait.wait_for_it(wait_helper, interval=.5, timeout=2)
File "/home/myron/repos/mojo.waiting/source/packages/ctxwait/waiting.py", line 103, in wait_for_it
    raise toerr
TimeoutError: Timeout waiting for 'wait_helper':
    timeout=2 start_time=2023-03-13 14:57:29.860302, end_time=2023-03-13 14:57:31.860302 now_time=2023-03-13 14:57:31.863681 time_diff=0:00:02.003379

The following is an example of how the mojo.waiting module is used.

from ctxwait import WaitContext, wait_for_it

def some_wait_helper(wctx: WaitContext):
    finished = False

    // TODO: Check if something is finished, the code and variables used
    //       here will show up in any tracebacks from pytest or testplus
    //       because the timeout is being raised in the appropriate scope.

    if not finished and wctx.final_attempt:
        whatfor = "Test timeout"
        toerr = wctx.create_timeout(whatfor)
        raise toerr

    return finished

wait_for_it(some_wait_helper)

The wait_for_it method has many different parameters that can be used to override the behavior of the wait loop.

def wait_for_it(looper: WaitCallback, *largs, what_for: Optional[str]=None, delay: float=DEFAULT_WAIT_DELAY,
            interval: float=DEFAULT_WAIT_INTERVAL, timeout: float=DEFAULT_WAIT_TIMEOUT,
            lkwargs: Dict[Any, Any]={}, wctx: Optional[WaitContext]=None):
    """
        Provides for convenient mechanism to wait for criteria to be met before proceeding.

        :param looper: A callback method that is repeatedly called while it returns `False` up-to
                    the end of a timeout period, and that will return `True` if a waited on
                    condition is met prior to a timeout condition being met.
        :param largs: Arguements to pass to the looper callback function.
        :param what_for: A breif description of what is being waited for.
        :param delay: An initial time delay to consume before beginning the waiting process.
        :param interval: A period of time to delay between rechecks of the wait conditon
        :param timeout: The maximum period of time in seconds that should be waited before timing out.
        :param lkwargs: Additional keyword arguments to pass to the looper function

        :raises TimeoutError: A timeout error with details around the wait condition.

        ..note: The 'delay', 'interval' and 'timeout' parameters will be ignored if the 'wctx' parameter
                is passed as the wctx (WaitContext) parameter includes these values with it.
    """
    ...

The wait_for_it function must be passed a method that follows the WaitCallback protocol. The function can have variable arguments and keyword arguements but the first parameter to the WaitCallback method must be a WaitContext object.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mojo_waiting-1.3.5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

mojo_waiting-1.3.5-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file mojo_waiting-1.3.5.tar.gz.

File metadata

  • Download URL: mojo_waiting-1.3.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.12.1 Darwin/23.5.0

File hashes

Hashes for mojo_waiting-1.3.5.tar.gz
Algorithm Hash digest
SHA256 ae5dda4bcd969ebd1d2c321f89575fd8252bb0b08684b1c9e591dec81c74061e
MD5 250fd6b51bdb7e3ef460d6100537b4db
BLAKE2b-256 266ac7fd1dc9382da67f3b54ee7561cfcf13ee27a35f5974b4d024d4c24e6b5a

See more details on using hashes here.

File details

Details for the file mojo_waiting-1.3.5-py3-none-any.whl.

File metadata

  • Download URL: mojo_waiting-1.3.5-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.0 CPython/3.12.1 Darwin/23.5.0

File hashes

Hashes for mojo_waiting-1.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f07350880f0a983405c45bc5d6a586f01f73d17a33b60608e5cd12373d946196
MD5 e7c106895cc4d9a91d41397495d6a832
BLAKE2b-256 aacb9b2e4095b2c9a5fa5e7f108ce6a6ff13a38a285ae3f2f64738e98424de05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page