def setUp(self): import vumi.sentry self.client = DummySentryClient() self.patch(vumi.sentry, 'vumi_raven_client', lambda dsn: self.client) self.logger = LogPublisher() self.service = SentryLoggerService("http://example.com/", "test.logger", "worker-1", logger=self.logger)
def makeService(self, options): sentry_dsn = options.vumi_options.pop('sentry', None) class_name = options.worker_class.rpartition('.')[2].lower() logger_name = options.worker_config.get('worker_name', class_name) system_id = options.vumi_options.get('system-id', 'global') worker_id = generate_worker_id(system_id, logger_name) worker_creator = WorkerCreator(options.vumi_options) worker = worker_creator.create_worker(options.worker_class, options.worker_config) if sentry_dsn is not None: sentry_service = SentryLoggerService(sentry_dsn, logger_name, worker_id) worker.addService(sentry_service) return worker
class TestSentryLoggerSerivce(VumiTestCase): def setUp(self): import vumi.sentry self.client = DummySentryClient() self.patch(vumi.sentry, 'vumi_raven_client', lambda dsn: self.client) self.logger = LogPublisher() self.service = SentryLoggerService("http://example.com/", "test.logger", "worker-1", logger=self.logger) @inlineCallbacks def test_logging(self): yield self.service.startService() self.logger.msg("Hello", logLevel=logging.WARN) self.assertEqual(self.client.messages, [(("Hello", ), { 'data': { 'level': 30, 'logger': 'test.logger' }, 'tags': { 'worker-id': 'worker-1' } })]) del self.client.messages[:] yield self.service.stopService() self.logger.msg("Foo", logLevel=logging.WARN) self.assertEqual(self.client.messages, []) @inlineCallbacks def test_stop_not_running(self): yield self.service.stopService() self.assertFalse(self.service.running) @inlineCallbacks def test_start_stop(self): self.assertFalse(self.service.registered()) self.assertEqual(self.client.teardowns, 0) yield self.service.startService() self.assertTrue(self.service.registered()) yield self.service.stopService() self.assertFalse(self.service.registered()) self.assertEqual(self.client.teardowns, 1)
class TestSentryLoggerSerivce(VumiTestCase): def setUp(self): import vumi.sentry self.client = DummySentryClient() self.patch(vumi.sentry, 'vumi_raven_client', lambda dsn: self.client) self.logger = LogPublisher() self.service = SentryLoggerService("http://example.com/", "test.logger", "worker-1", logger=self.logger) @inlineCallbacks def test_logging(self): yield self.service.startService() self.logger.msg("Hello", logLevel=logging.WARN) self.assertEqual(self.client.messages, [ (("Hello",), {'data': {'level': 30, 'logger': 'test.logger'}, 'tags': {'worker-id': 'worker-1'}}) ]) del self.client.messages[:] yield self.service.stopService() self.logger.msg("Foo", logLevel=logging.WARN) self.assertEqual(self.client.messages, []) @inlineCallbacks def test_stop_not_running(self): yield self.service.stopService() self.assertFalse(self.service.running) @inlineCallbacks def test_start_stop(self): self.assertFalse(self.service.registered()) self.assertEqual(self.client.teardowns, 0) yield self.service.startService() self.assertTrue(self.service.registered()) yield self.service.stopService() self.assertFalse(self.service.registered()) self.assertEqual(self.client.teardowns, 1)