Exemplo n.º 1
0
 def test_periodic_task_close(self):
     mock_func = mock.Mock()
     task = transport.PeriodicMetricTask(100, mock_func)
     task.start()
     mock_func.assert_not_called()
     task.close()
     self.assertEqual(mock_func.call_count, 1)
Exemplo n.º 2
0
 def test_periodic_task_cancel(self):
     mock_func = mock.Mock()
     task = transport.PeriodicMetricTask(INTERVAL, mock_func)
     task.start()
     time.sleep(INTERVAL + INTERVAL / 2.0)
     self.assertEqual(mock_func.call_count, 1)
     task.cancel()
     time.sleep(INTERVAL)
     self.assertEqual(mock_func.call_count, 1)
Exemplo n.º 3
0
 def test_periodic_task_not_started(self):
     mock_func = mock.Mock()
     task = transport.PeriodicMetricTask(INTERVAL, mock_func)
     time.sleep(INTERVAL + INTERVAL / 2.0)
     mock_func.assert_not_called()
     task.cancel()
Exemplo n.º 4
0
 def test_default_constructor(self):
     mock_func = mock.Mock()
     task = transport.PeriodicMetricTask(function=mock_func)
     self.assertEqual(task.func, mock_func)
     self.assertEqual(task.interval, transport.DEFAULT_INTERVAL)