Ejemplo n.º 1
0
    def test_sleeps(self, mock_sleep, mock_check_workers):
        # raising an exception is the only way we have to break out of the
        # infinite loop
        mock_sleep.side_effect = self.SleepException

        self.assertRaises(self.SleepException, scheduler.WorkerTimeoutMonitor().run)

        # verify the frequency
        mock_sleep.assert_called_once_with(60)
Ejemplo n.º 2
0
    def test_deletes_workers(self, mock_worker, mock_delete_worker):
        mock_worker.objects.return_value = [
            Worker('name1', datetime.utcnow()),
            Worker('name2', datetime.utcnow()),
        ]

        scheduler.WorkerTimeoutMonitor().check_workers()

        # make sure _delete_worker is only called for the two expected calls
        mock_delete_worker.assert_has_calls([mock.call('name1'), mock.call('name2')])
Ejemplo n.º 3
0
    def test_logs_exception(self, mock_sleep, mock_check_workers, mock_log_error):

        # raising an exception is the only way we have to break out of the
        # infinite loop
        mock_check_workers.side_effect = self.SleepException
        mock_log_error.side_effect = self.SleepException

        self.assertRaises(self.SleepException, scheduler.WorkerTimeoutMonitor().run)

        self.assertEqual(mock_log_error.call_count, 1)
Ejemplo n.º 4
0
    def test_checks_workers(self, mock_sleep, mock_check_workers, mock_log_error):

        # raising an exception is the only way we have to break out of the
        # infinite loop
        mock_check_workers.side_effect = self.SleepException
        mock_log_error.side_effect = self.SleepException

        self.assertRaises(self.SleepException, scheduler.WorkerTimeoutMonitor().run)

        mock_check_workers.assert_called_once_with()
Ejemplo n.º 5
0
    def test_deletes_workers(self, mock_filter, mock_delete):
        mock_filter.return_value = [
            resources.Worker('name1', datetime.utcnow()),
            resources.Worker('name2', datetime.utcnow()),
        ]

        scheduler.WorkerTimeoutMonitor().check_workers()

        # make sure only these two queues were deleted
        mock_delete.assert_any_call(args=('name1', ),
                                    queue=RESOURCE_MANAGER_QUEUE)
        mock_delete.assert_any_call(args=('name2', ),
                                    queue=RESOURCE_MANAGER_QUEUE)
        self.assertEqual(mock_delete.call_count, 2)
Ejemplo n.º 6
0
    def test_calls_filter(self, mock_filter):
        mock_filter.return_value = []

        scheduler.WorkerTimeoutMonitor().check_workers()

        # verify that filter was called with the right argument
        self.assertEqual(mock_filter.call_count, 1)
        self.assertEqual(len(mock_filter.call_args[0]), 1)
        call_arg = mock_filter.call_args[0][0]
        self.assertTrue(isinstance(call_arg, Criteria))

        # make sure the timestamp being searched for is within the appropriate timeout,
        # plus a 1-second grace period to account for execution time of test code.
        timestamp = call_arg.filters['last_heartbeat']['$lt']
        self.assertTrue(isinstance(timestamp, datetime))
        self.assertTrue(datetime.utcnow() - timestamp < timedelta(
            scheduler.WorkerTimeoutMonitor.WORKER_TIMEOUT_SECONDS + 1))