MCPcopy Create free account
hub / github.com/dot-agent/nextpy / test_background_task

Function test_background_task

integration/test_background_task.py:162–214  ·  view source on GitHub ↗

Test that background tasks work as expected. Args: background_task: harness for BackgroundTask app. driver: WebDriver instance. token: The token for the connected client.

(
    background_task: AppHarness,
    driver: WebDriver,
    token: str,
)

Source from the content-addressed store, hash-verified

160
161
162def test_background_task(
163 background_task: AppHarness,
164 driver: WebDriver,
165 token: str,
166):
167 """Test that background tasks work as expected.
168
169 Args:
170 background_task: harness for BackgroundTask app.
171 driver: WebDriver instance.
172 token: The token for the connected client.
173 """
174 assert background_task.app_instance is not None
175
176 # get a reference to all buttons
177 delayed_increment_button = driver.find_element(By.ID, "delayed-increment")
178 yield_increment_button = driver.find_element(By.ID, "yield-increment")
179 increment_button = driver.find_element(By.ID, "increment")
180 blocking_pause_button = driver.find_element(By.ID, "blocking-pause")
181 non_blocking_pause_button = driver.find_element(By.ID, "non-blocking-pause")
182 driver.find_element(By.ID, "reset")
183
184 # get a reference to the counter
185 counter = driver.find_element(By.ID, "counter")
186
187 # get a reference to the iterations input
188 iterations_input = driver.find_element(By.ID, "iterations")
189
190 # kick off background tasks
191 iterations_input.clear()
192 iterations_input.send_keys("50")
193 delayed_increment_button.click()
194 blocking_pause_button.click()
195 delayed_increment_button.click()
196 for _ in range(10):
197 increment_button.click()
198 blocking_pause_button.click()
199 delayed_increment_button.click()
200 delayed_increment_button.click()
201 yield_increment_button.click()
202 non_blocking_pause_button.click()
203 yield_increment_button.click()
204 blocking_pause_button.click()
205 yield_increment_button.click()
206 for _ in range(10):
207 increment_button.click()
208 yield_increment_button.click()
209 blocking_pause_button.click()
210 assert background_task._poll_for(lambda: counter.text == "420", timeout=40)
211 # all tasks should have exited and cleaned up
212 assert background_task._poll_for(
213 lambda: not background_task.app_instance.background_tasks # type: ignore
214 )

Callers

nothing calls this directly

Calls 2

rangeFunction · 0.50
clearMethod · 0.45

Tested by

no test coverage detected