Exemplo n.º 1
0
    def test_buffers_runtime_info(self):
        """Make sure we send the buffers size info."""
        stats_worker = StatsWorker(self.service, 10)
        # add some info the all the buffers we know
        mock = mocker.Mocker()
        producer = mock.mock()
        upload.MultipartUploadFactory.buffers_size = 0
        mp = upload.MultipartUploadFactory(None, producer, 1024, 2048,
                                           0, 1042, 10)
        mp.dataReceived('a' * 10)
        client = mock.mock()
        http_client.HTTPProducer.buffers_size = 0
        http_prod = http_client.HTTPProducer(client)
        self.addCleanup(http_prod.timeout_call.cancel)
        http_prod.dataReceived('a' * 20)
        producers.S3Producer.buffers_size = 0
        s3_prod = producers.S3Producer(1024)
        s3_prod.dataReceived('a' * 30)

        stats_worker.runtime_info()
        self.assertIn(('gauge', 'buffers_size.HTTPProducer', 20),
                      self.metrics.calls)
        self.assertIn(('gauge', 'buffers_size.MultipartUploadFactory', 10),
                      self.metrics.calls)
        self.assertIn(('gauge', 'buffers_size.S3Producer', 30),
                      self.metrics.calls)
Exemplo n.º 2
0
    def test_buffers_runtime_info(self):
        """Make sure we send the buffers size info."""
        stats_worker = StatsWorker(self.service, 10)
        # add some info the all the buffers we know
        mock = mocker.Mocker()
        producer = mock.mock()
        upload.MultipartUploadFactory.buffers_size = 0
        mp = upload.MultipartUploadFactory(None, producer, 1024, 2048, 0, 1042,
                                           10)
        mp.dataReceived('a' * 10)
        client = mock.mock()
        http_client.HTTPProducer.buffers_size = 0
        http_prod = http_client.HTTPProducer(client)
        self.addCleanup(http_prod.timeout_call.cancel)
        http_prod.dataReceived('a' * 20)
        producers.S3Producer.buffers_size = 0
        s3_prod = producers.S3Producer(1024)
        s3_prod.dataReceived('a' * 30)

        stats_worker.runtime_info()
        self.assertIn(('gauge', 'buffers_size.HTTPProducer', 20),
                      self.metrics.calls)
        self.assertIn(('gauge', 'buffers_size.MultipartUploadFactory', 10),
                      self.metrics.calls)
        self.assertIn(('gauge', 'buffers_size.S3Producer', 30),
                      self.metrics.calls)
Exemplo n.º 3
0
 def test_runtime_info(self):
     """Make sure we add runtime info."""
     stats_worker = StatsWorker(self.service, 10)
     # get the reactor
     from twisted.internet import reactor
     stats_worker.runtime_info()
     # check the reactor data
     self.assertIn(('gauge', 'reactor.readers',
                    len(reactor.getReaders())), self.metrics.calls)
     self.assertIn(('gauge', 'reactor.writers',
                    len(reactor.getWriters())), self.metrics.calls)
Exemplo n.º 4
0
 def test_runtime_info(self):
     """Make sure we add runtime info."""
     stats_worker = StatsWorker(self.service, 10)
     # get the reactor
     from twisted.internet import reactor
     stats_worker.runtime_info()
     # check the reactor data
     self.assertIn(('gauge', 'reactor.readers', len(reactor.getReaders())),
                   self.metrics.calls)
     self.assertIn(('gauge', 'reactor.writers', len(reactor.getWriters())),
                   self.metrics.calls)
Exemplo n.º 5
0
 def test_stats_loop(self):
     """Test that the StatsWorker loop works as expected."""
     stats_worker = StatsWorker(self.service, 2)
     clock = task.Clock()
     stats_worker.callLater = clock.callLater
     failure = defer.failure.Failure(ValueError('error!'))
     stats_worker.deferToThread = lambda _: defer.fail(failure)
     stats_worker.start()
     clock.advance(1)
     delayed_calls = clock.getDelayedCalls()
     self.assertEqual(len(delayed_calls), 1)
     self.assertIn(stats_worker.next_loop, delayed_calls)
     stats_worker.stop()
Exemplo n.º 6
0
 def test_stats_loop(self):
     """Test that the StatsWorker loop works as expected."""
     stats_worker = StatsWorker(self.service, 2)
     clock = task.Clock()
     stats_worker.callLater = clock.callLater
     failure = defer.failure.Failure(ValueError('error!'))
     stats_worker.deferToThread = lambda _: defer.fail(failure)
     stats_worker.start()
     clock.advance(1)
     delayed_calls = clock.getDelayedCalls()
     self.assertEqual(len(delayed_calls), 1)
     self.assertIn(stats_worker.next_loop, delayed_calls)
     stats_worker.stop()