@@ -344,6 +344,50 @@ def test_no_email_sent_after_removed(self):
344344 pushers = list (pushers )
345345 self .assertEqual (len (pushers ), 0 )
346346
347+ def test_remove_unlinked_pushers_background_job (self ):
348+ """Checks that all existing pushers associated with unlinked email addresses are removed
349+ upon running the remove_deleted_email_pushers background update.
350+ """
351+ # disassociate the user's email address manually (without deleting the pusher).
352+ # This resembles the old behaviour, which the background update below is intended
353+ # to clean up.
354+ self .get_success (
355+ self .hs .get_datastore ().user_delete_threepid (
356+ self .
user_id ,
"email" ,
"[email protected] " 357+ )
358+ )
359+
360+ # Run the "remove_deleted_email_pushers" background job
361+ self .get_success (
362+ self .hs .get_datastore ().db_pool .simple_insert (
363+ table = "background_updates" ,
364+ values = {
365+ "update_name" : "remove_deleted_email_pushers" ,
366+ "progress_json" : "{}" ,
367+ "depends_on" : None ,
368+ },
369+ )
370+ )
371+
372+ # ... and tell the DataStore that it hasn't finished all updates yet
373+ self .hs .get_datastore ().db_pool .updates ._all_done = False
374+
375+ # Now let's actually drive the updates to completion
376+ while not self .get_success (
377+ self .hs .get_datastore ().db_pool .updates .has_completed_background_updates ()
378+ ):
379+ self .get_success (
380+ self .hs .get_datastore ().db_pool .updates .do_next_background_update (100 ),
381+ by = 0.1 ,
382+ )
383+
384+ # Check that all pushers with unlinked addresses were deleted
385+ pushers = self .get_success (
386+ self .hs .get_datastore ().get_pushers_by ({"user_name" : self .user_id })
387+ )
388+ pushers = list (pushers )
389+ self .assertEqual (len (pushers ), 0 )
390+
347391 def _check_for_mail (self ):
348392 """Check that the user receives an email notification"""
349393
0 commit comments