WaitCondition: last_check >= {last_check}
WaitTimeout: {wait_timeout}
WaitTrigger: check
Columns: last_check state plugin_output
Filter: host_name = {host}
Localtime: {localtime}
OutputFormat: python
KeepAlive: on
ResponseHeader: fixed16
ColumnHeaders: true

'''.format(last_check=now, localtime=now, host=host, now=now, cmd=command,
           wait_timeout=wait_timeout_sec * 1000, # WaitTimeout header field is in millisecs
        )

        t0 = time.time()
        response = self.query_livestatus(request)
        t1 = time.time()
        self.assertLess(wait_timeout_sec, t1 - t0,
                        '(actually and in this very specific case) livestatus should take at least the requested WaitTimeout (%s sec) to complete ; response=%s' %
                        (wait_timeout_sec, response))
        goodresponse = "200          13\n[[0, 0, '']]\n"
        self.assertEqual(goodresponse, response)
        data = self.livestatus_broker.from_q.get(block=False)
        self.assertIsInstance(data, ExternalCommand)
        self.assertEqual(command, data.cmd_line)


if __name__ == '__main__':
    unittest.main()
        profile.runctx('profile_bp_rule_macro_expand()', globals(), locals())

        print "Profiling with macro modulation"

        def profile_bp_rule_macro_modulated():
            svc_cor = self.sched.services.find_srv_by_name_and_hostname("dummy_modulated", "bprule_macro_modulated")
            for i in range(1000):
                self.scheduler_loop(2, [[svc_cor, None, None]], do_sleep=True, verbose=False)

        profile.runctx('profile_bp_rule_macro_modulated()', globals(), locals())


class TestConfigBroken(ShinkenTest):

    def setUp(self):
        self.setup_with_file('etc/shinken_business_correlator_expand_expression_broken.cfg')

    def test_hostgroup_expansion_errors(self):
        self.assert_(not self.conf.conf_is_correct)

        # Get the arbiter's log broks
        [b.prepare() for b in self.broks.values()]
        logs = [b.data['log'] for b in self.broks.values() if b.type == 'log']

        self.assert_(len([log for log in logs if re.search('Business rule uses invalid regex', log)]) == 1)
        self.assert_(len([log for log in logs if re.search('Business rule got an empty result', log)]) == 3)


if __name__ == '__main__':
    unittest.main()