MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / submit_and_wait_for_completion

Function submit_and_wait_for_completion

tests/unit/io/utils.py:102–136  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

100
101
102def 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
139def noop_if_monkey_patched(f):

Callers 1

Calls 6

was_invokedMethod · 0.95
get_wait_timeMethod · 0.95
get_timeoutFunction · 0.85
TimerCallbackClass · 0.85
sleepMethod · 0.80
removeMethod · 0.45

Tested by 1