示例#1
0
 def test_processing_metrics(self):
     filename = write_spool()
     forwarder = MetricForwarder(self.config, self.shutdown)
     forwarder.request_session = FakeSession()
     forwarder.start()
     while len(forwarder.request_session.metrics_posted) < 10:
         if forwarder.should_send_batch():
             forwarder.forward()
         time.sleep(0.1)
     self.shutdown.set()
     shutdown(forwarder)
     # we only have 10 valid metrics.
     self.assertEqual(len(forwarder.request_session.metrics_posted), 10)
     self.remove_spool(filename)
示例#2
0
 def test_empty_post(self, sleep):
     filename = write_spool(empty=True)
     forwarder = MetricForwarder(self.config, self.shutdown)
     forwarder.request_session = FakeSession()
     forwarder.start()
     if forwarder.should_send_batch():
         forwarder.forward()
     time.sleep(0.1)
     self.shutdown.set()
     shutdown(forwarder)
     metrics_posted = forwarder.request_session.metrics_posted
     invalid_posts = forwarder.request_session.invalid_posts
     self.assertFalse(forwarder.request_session.is_called)
     self.assertEqual(len(metrics_posted), 0)
     self.assertEqual(len(invalid_posts), 0)
     self.remove_spool(filename)
示例#3
0
 def test_post_failure(self, sleep):
     sleep.return_value = True
     filename = write_spool(size=10)
     forwarder = MetricForwarder(self.config, self.shutdown)
     forwarder.request_session = FakeSession()
     forwarder.request_session.should_fail = True
     forwarder.start()
     while len(forwarder.request_session.metrics_posted) < 10:
         if forwarder.should_send_batch():
             forwarder.forward()
         time.sleep(1)
     self.shutdown.set()
     shutdown(forwarder)
     metrics_posted = forwarder.request_session.metrics_posted
     invalid_posts = forwarder.request_session.invalid_posts
     self.assertTrue(forwarder.request_session.is_called)
     self.assertEqual(len(metrics_posted), 10)
     self.assertEqual(len(invalid_posts), 10)
     self.assertIn(invalid_posts[0], metrics_posted)
     self.remove_spool(filename)
示例#4
0
 def test_tcp_single_dp_spool(self):
     tcp_config_sock = patch('hg_agent_forwarder.receiver.socket')
     tcp_mock_sock = self.tcp_config_sock.start()
     tcp_mock_sock.socket.return_value = MockedTcpRecvSocket()
     tcp_receiver = MetricReceiverTcp(self.config)
     my_spool = tcp_receiver.spool
     tcp_receiver._sock.set_metric(self.test_metric, 20)
     setup_tcp_receiver(tcp_receiver)
     forwarder = MetricForwarder(self.config, self.shutdown)
     forwarder.request_session = FakeSession()
     forwarder.start()
     while len(forwarder.request_session.metrics_posted) < 1:
         if forwarder.should_send_batch():
             forwarder.forward()
         time.sleep(0.01)
     tcp_receiver.shutdown()
     self.assertEqual(len(my_spool.lookup_spools()), 1)
     self.shutdown.set()
     shutdown(forwarder)
     # we only have 1 valid metric.
     self.assertEqual(len(my_spool.lookup_spools()), 1)
     self.assertEqual(len(forwarder.request_session.metrics_posted), 1)
fake_session = FakeSession({
    'sitematrix': {
        'count':
        4,
        '0': {
            'code':
            'en',
            'name':
            'English',
            'site': [
                {
                    'url': 'https://en.wikipedia.org',
                    'dbname': 'enwiki',
                    'code': 'wiki',
                    'sitename': 'Wikipedia',
                },
                {
                    'url': 'https://en.wiktionary.org',
                    'dbname': 'enwiktionary',
                    'code': 'wiktionary',
                    'sitename': 'Wiktionary',
                },
            ],
            'dir':
            'ltr',
            'localname':
            'English',
        },
        '1': {
            'code':
            'pt',
            'name':
            'português',
            'site': [
                {
                    'url': 'https://pt.wikipedia.org',
                    'dbname': 'ptwiki',
                    'code': 'wiki',
                    'sitename': 'Wikipedia',
                },
            ],
            'dir':
            'ltr',
            'localname':
            'Portuguese',
        },
        'specials': [
            {
                'url': 'https://www.wikidata.org',
                'dbname': 'wikidatawiki',
                'code': 'wikidata',
                'lang': 'wikidata',
                'sitename': 'Wikipedia',
            },
        ],
    },
})