MCPcopy
hub / github.com/celery/celery / test_eta

Method test_eta

t/integration/test_tasks.py:196–222  ·  view source on GitHub ↗

Tests tasks scheduled at some point in future.

(self, manager)

Source from the content-addressed store, hash-verified

194
195 @flaky
196 def test_eta(self, manager):
197 """Tests tasks scheduled at some point in future."""
198 start = time.perf_counter()
199 # Schedule task to be executed in 3 seconds
200 result = add.apply_async((1, 1), countdown=3)
201 time.sleep(1)
202 assert result.status == 'PENDING'
203 assert result.ready() is False
204 assert result.get() == 2
205 end = time.perf_counter()
206 assert result.status == 'SUCCESS'
207 assert result.ready() is True
208 # Difference between calling the task and result must be bigger than 3 secs
209 assert (end - start) > 3
210
211 start = time.perf_counter()
212 # Schedule task to be executed at time now + 3 seconds
213 result = add.apply_async((2, 2), eta=datetime.now(timezone.utc) + timedelta(seconds=3))
214 time.sleep(1)
215 assert result.status == 'PENDING'
216 assert result.ready() is False
217 assert result.get() == 4
218 end = time.perf_counter()
219 assert result.status == 'SUCCESS'
220 assert result.ready() is True
221 # Difference between calling the task and result must be bigger than 3 secs
222 assert (end - start) > 3
223
224 @flaky
225 def test_fail(self, manager):

Callers

nothing calls this directly

Calls 5

apply_asyncMethod · 0.45
sleepMethod · 0.45
readyMethod · 0.45
getMethod · 0.45
nowMethod · 0.45

Tested by

no test coverage detected