'Test that client killed messages are handled correctly for hunts.'

def testAlertEmailIsSentWhenClientKilledDuringHunt(self):

    self.email_messages = []
    def SendEmail(address, sender, title, message, **_):
        self.email_messages.append(dict(address=address, sender=sender, title=title, message=message))
    with hunts_implementation.GRRHunt.StartHunt(hunt_name=hunts_standard.GenericHunt.__name__, flow_runner_args=rdf_flows.FlowRunnerArgs(flow_name=flow_test_lib.FlowWithOneClientRequest.__name__), client_rate=0, crash_alert_email='crashes@example.com', token=self.token) as hunt:
        hunt.Run()
        hunt.StartClients(hunt.session_id, self.client_id)
    with utils.Stubber(email_alerts.EMAIL_ALERTER, 'SendEmail', SendEmail):
        client = flow_test_lib.CrashClientMock(self.client_id, self.token)
        hunt_test_lib.TestHuntHelper(client, [self.client_id], token=self.token, check_flow_errors=False)
    self.assertEqual(len(self.email_messages), 2)
    self.assertListEqual([self.email_messages[0]['address'], self.email_messages[1]['address']], ['crashes@example.com', config.CONFIG['Monitoring.alert_email']])
