def test_start_and_shutdown_with_configured_queue_processor(self): start_time = time() destination = StubDestination(10) server = Server() processor = server.create_queue_processor() processor.set_destinations([destination]) processor.flush_interval = 0.5 server.queue_processor = processor metric = Counter('test.metric', 1) collector = StubCollector(data=metric.to_request(), frequency=10) server.set_collectors([collector]) server_thread = Thread(target=server.start) server_thread.setDaemon(True) server_thread.start() server.wait_until_running(5) self.assertTrue(server.is_running()) destination.wait_until_expected_count_items(10) server.shutdown() server.wait_until_shutdown(5) self.assertFalse(server.is_running()) self.assertFalse(server_thread.isAlive()) self.assertFalse(collector.is_queuing_requests()) self.assertFalse(processor.is_processing()) self.assertGreaterEqual(len(destination.metrics), 10) for metric in destination.metrics: self.assertEqual(3, len(metric)) self.assertEqual(metric[0], "test.metric") self.assertGreaterEqual(metric[1], 0) self.assertGreaterEqual(metric[2], start_time)
def test_server_creates_a_default_queue_processor_without_destination( self): server = Server() collector = StubCollector('-') server.set_collectors([collector]) server_thread = Thread(target=server.start) server_thread.setDaemon(True) server_thread.start() server.wait_until_running(5) self.assertTrue(server.is_running()) server.shutdown() server.wait_until_shutdown(5) self.assertFalse(server.is_running()) self.assertFalse(server_thread.isAlive())