'Tests if we can stop a hunt.'

def testStopping(self):

    foreman = aff4.FACTORY.Open('aff4:/foreman', mode='rw', token=self.token)
    rules = foreman.Get(foreman.Schema.RULES)
    self.assertEqual(len(rules), 0)
    now = rdfvalue.RDFDatetime.Now()
    expires = rdfvalue.Duration('1h').Expiry()
    rules = [rdf_foreman.ForemanRule(created=now, expires=expires, description='Test    rule1'), rdf_foreman.ForemanRule(created=now, expires=expires, description='Test    rule2')]
    self.AddForemanRules(rules)
    client_rule_set = rdf_foreman.ForemanClientRuleSet(rules=[rdf_foreman.ForemanClientRule(rule_type=rdf_foreman.ForemanClientRule.Type.REGEX, regex=rdf_foreman.ForemanRegexClientRule(attribute_name='GRR    client', attribute_regex='HUNT')), rdf_foreman.ForemanClientRule(rule_type=rdf_foreman.ForemanClientRule.Type.INTEGER, integer=rdf_foreman.ForemanIntegerClientRule(attribute_name='Clock', operator=rdf_foreman.ForemanIntegerClientRule.Operator.GREATER_THAN, value=1336650631137737))])
    hunt = implementation.GRRHunt.StartHunt(hunt_name=standard.SampleHunt.__name__, client_rule_set=client_rule_set, client_rate=0, token=self.token)
    with hunt:
        runner = hunt.GetRunner()
        runner.Start()
        rules = [rdf_foreman.ForemanRule(created=now, expires=expires, description='Test    rule3'), rdf_foreman.ForemanRule(created=now, expires=expires, description='Test    rule4')]
        self.AddForemanRules(rules)
        foreman = aff4.FACTORY.Open('aff4:/foreman', mode='rw', token=self.token)
        rules = foreman.Get(foreman.Schema.RULES)
        self.assertEqual(len(rules), 5)
        self.assertTrue(runner.IsHuntStarted())
        hunt.Stop()
    foreman = aff4.FACTORY.Open('aff4:/foreman', mode='rw', token=self.token)
    rules = foreman.Get(foreman.Schema.RULES)
    self.assertEqual(len(rules), 4)
    with hunt:
        self.assertFalse(hunt.GetRunner().IsHuntStarted())
