@@ -229,6 +229,43 @@ def foo(moo: int):
229229 foo .apply_async .assert_called ()
230230 assert foo .apply_async .call_args [0 ][0 ] == [101 ]
231231
232+ def test_apply_async_sets_eta (self ):
233+
234+ @self .app .task (shared = False )
235+ def foo ():
236+ pass
237+ foo .apply_async = Mock (name = 'foo.apply_async' )
238+
239+ scheduler = mScheduler (app = self .app )
240+ entry = scheduler .Entry (task = foo .name , app = self .app ,
241+ schedule = always_due )
242+ scheduler .apply_async (entry , advance = False )
243+ assert "eta" in foo .apply_async .call_args .kwargs
244+ kwarg_eta = foo .apply_async .call_args .kwargs ["eta" ]
245+ # Mock scheduler has a frequency of 1 second
246+ expected_eta = datetime .now (tz = pytz .utc ) + timedelta (seconds = 1 )
247+ difference = kwarg_eta - expected_eta
248+ # ETA received by the task should be approx equal to current time
249+ assert abs (difference ) < timedelta (seconds = 1 )
250+
251+ def test_apply_async_keeps_existing_eta (self ):
252+
253+ @self .app .task (shared = False )
254+ def foo ():
255+ pass
256+ foo .apply_async = Mock (name = 'foo.apply_async' )
257+
258+ scheduler = mScheduler (app = self .app )
259+ preset_eta = datetime (2000 , 10 , 10 , 10 , 10 , 10 , 10 , tzinfo = pytz .utc )
260+ entry = scheduler .Entry (task = foo .name , app = self .app ,
261+ options = {"eta" : preset_eta },
262+ schedule = always_due )
263+ scheduler .apply_async (entry , advance = False )
264+ assert "eta" in foo .apply_async .call_args .kwargs
265+ kwarg_eta = foo .apply_async .call_args .kwargs ["eta" ]
266+ # The *exact* value of a given ETA should be passed to the task
267+ assert kwarg_eta == preset_eta
268+
232269 def test_should_sync (self ):
233270
234271 @self .app .task (shared = False )
0 commit comments