This will submit a number of timers to the provided connection. It will then ensure that the corresponding callback is invoked in the appropriate amount of time. :param unit_test: Invoking unit tests :param connection: Connection to create the timer on. :param start: Lower bound of
(unit_test, create_timer, start, end, increment, precision, split_range=False)
| 100 | |
| 101 | |
| 102 | def submit_and_wait_for_completion(unit_test, create_timer, start, end, increment, precision, split_range=False): |
| 103 | """ |
| 104 | This will submit a number of timers to the provided connection. It will then ensure that the corresponding |
| 105 | callback is invoked in the appropriate amount of time. |
| 106 | :param unit_test: Invoking unit tests |
| 107 | :param connection: Connection to create the timer on. |
| 108 | :param start: Lower bound of range. |
| 109 | :param end: Upper bound of the time range |
| 110 | :param increment: +1, or -1 |
| 111 | :param precision: 100 for centisecond, 1000 for milliseconds |
| 112 | :param split_range: True to split the range between incrementing and decrementing. |
| 113 | """ |
| 114 | |
| 115 | # Various lists for tracking callback as completed or pending |
| 116 | pending_callbacks = [] |
| 117 | completed_callbacks = [] |
| 118 | |
| 119 | # submit timers with various timeouts |
| 120 | for gross_time in range(start, end, increment): |
| 121 | timeout = get_timeout(gross_time, start, end, precision, split_range) |
| 122 | callback = TimerCallback(timeout) |
| 123 | create_timer(timeout, callback.invoke) |
| 124 | pending_callbacks.append(callback) |
| 125 | |
| 126 | # wait for all the callbacks associated with the timers to be invoked |
| 127 | while len(pending_callbacks) is not 0: |
| 128 | for callback in pending_callbacks: |
| 129 | if callback.was_invoked(): |
| 130 | pending_callbacks.remove(callback) |
| 131 | completed_callbacks.append(callback) |
| 132 | time.sleep(.1) |
| 133 | |
| 134 | # ensure they are all called back in a timely fashion |
| 135 | for callback in completed_callbacks: |
| 136 | unit_test.assertAlmostEqual(callback.expected_wait, callback.get_wait_time(), delta=.15) |
| 137 | |
| 138 | |
| 139 | def noop_if_monkey_patched(f): |