def test_worker_process_transactions(m): stats = Stats() input_queue = queue.Queue(2) retry_queue = queue.Queue(2) w = Worker(input_queue, retry_queue, stats) t_success = Transaction("data", "https://datadog.com", "/success", None) t_error = Transaction("data", "https://datadog.com", "/error", None) m.post("https://datadog.com/success", status_code=200) m.post("https://datadog.com/error", status_code=402) input_queue.put(t_success) input_queue.put(t_error) # process 2 transactions w._process_transactions() w._process_transactions() assert input_queue.empty() assert not retry_queue.empty() assert t_success.nb_try == 1 assert t_error.nb_try == 1 assert t_error.next_flush is not None retry_item = retry_queue.get() assert t_error == retry_item
def test_worker_stop(): input_queue = queue.Queue() retry_queue = queue.Queue() w = Worker(input_queue, retry_queue) w.start() w.stop() w.join(2) assert not w.isAlive()
def test_init(): input_queue = queue.Queue(2) retry_queue = queue.Queue(2) w = Worker(input_queue, retry_queue) assert w.input_queue == input_queue assert w.retry_queue == retry_queue rw = RetryWorker(input_queue, retry_queue) assert rw.input_queue == input_queue assert rw.retry_queue == retry_queue assert rw.transactions == [] assert rw.flush_interval == rw.DEFAULT_FLUSH_INTERVAL assert rw.retry_queue_max_size == 30 # default value from config