Example #1
0
    def test_switch_to_idle_mode(self):
        mocked_queue = MagicMock()
        mocked_idle = MagicMock(side_effect=ValueError)
        mocked_idle_event = MagicMock()

        mocked_queue.get.side_effect = Empty()

        with patch.multiple("gitfs.worker.sync", idle=mocked_idle_event):
            worker = SyncWorker(
                "name",
                "email",
                "name",
                "email",
                strategy="strategy",
                commit_queue=mocked_queue,
            )
            worker.on_idle = mocked_idle
            worker.timeout = 1
            worker.min_idle_times = -1

            with pytest.raises(ValueError):
                worker.work()

            mocked_queue.get.assert_called_once_with(timeout=1, block=True)
            assert mocked_idle_event.set.call_count == 1
            assert mocked_idle.call_count == 1
Example #2
0
 def get(self, **kwargs):
     from six.moves.queue import Empty
     self._got = kwargs
     try:
         return self._items.pop()
     except IndexError:
         raise Empty()
Example #3
0
    def __call__(self):

        if 0 < self.timeout:
            import time
            waittime = min(self.timeout, self.waittime)
            self.timeout -= self.waittime
            time.sleep(waittime)

        else:
            raise Empty("No data found in queue within timeout")
Example #4
0
    def test_work(self):
        mocked_queue = MagicMock()
        mocked_idle = MagicMock(side_effect=ValueError)

        mocked_queue.get.side_effect = Empty()

        worker = SyncWorker("name", "email", "name", "email",
                            strategy="strategy", commit_queue=mocked_queue)
        worker.on_idle = mocked_idle
        worker.timeout = 1
        worker.min_idle_times = 1

        with pytest.raises(ValueError):
            worker.work()

        mocked_queue.get.assert_called_once_with(timeout=1, block=True)
        assert mocked_idle.call_count == 1
Example #5
0
    def __call__(self):

        raise Empty("No data found in queue")
Example #6
0
 def get(self, timeout=None):
     if self.cin.poll(timeout):
         return self.cin.recv()
     else:
         raise Empty()
Example #7
0
 def get(self, *args, **kwargs):
     try:
         return self.q.pop(0)
     except IndexError:
         raise Empty()