Exemplo n.º 1
0
 def get_expired_timers(self, deadline):
     return {
         i: [
             TimerRequest(i, f"test_{i}_0", 0),
             TimerRequest(i, f"test_{i}_1", 0)
         ]
         for i in range(1, 4)
     }
Exemplo n.º 2
0
 def _enqueue_on_interval(mp_queue, n, interval, sem):
     """
     enqueues ``n`` timer requests into ``mp_queue`` one element per
     interval seconds. Releases the given semaphore once before going to work.
     """
     sem.release()
     for i in range(0, n):
         mp_queue.put(TimerRequest(i, "test_scope", 0))
         time.sleep(interval)
Exemplo n.º 3
0
        def test_get(self):
            mp_queue = mp.Queue()
            request_queue = MultiprocessingRequestQueue(mp_queue)

            requests = request_queue.get(1, timeout=0.01)
            self.assertEqual(0, len(requests))

            request = TimerRequest(1, "test_scope", 0)
            mp_queue.put(request)
            requests = request_queue.get(2, timeout=0.01)
            self.assertEqual(1, len(requests))
            self.assertIn(request, requests)
Exemplo n.º 4
0
 def _release_timer(self, pid, scope):
     return TimerRequest(worker_id=pid, scope_id=scope, expiration_time=-1)
Exemplo n.º 5
0
 def _valid_timer(self, pid, scope):
     valid = time.time() + 60
     return TimerRequest(worker_id=pid, scope_id=scope, expiration_time=valid)
Exemplo n.º 6
0
 def _expired_timer(self, pid, scope):
     expired = time.time() - 60
     return TimerRequest(worker_id=pid, scope_id=scope, expiration_time=expired)
Exemplo n.º 7
0
 def get(self, size, timeout):
     return [TimerRequest(1, "test_1", 0), TimerRequest(2, "test_2", 0)]