def test_flush_when_worker_stopped_halts(self, t): t = Transport() t.worker = ThreadedWorker(t) assert_transport(t) assert t.running is True t.flush() assert t.running is False
def test_stop_when_worker_stopped(self, t): t = Transport() t.worker = ThreadedWorker(t) assert_transport(t) assert t.running is True t.stop() assert t.running is False
def test_emit_when_worker_stopped_halts(self, t): class TWorker(Worker): def work(self, timeout): raise WorkerStoppedError t = Transport() t.worker = TWorker(t) assert_transport(t) assert t.running is True t.emit(tjson()) assert t.running is False
def test_halt_group_when_stopped(self): for n in range(1, 4): tps = [Transport(worker_class=Worker) for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.halt() assert_group_stopped(g, tps)
def test_ctx_manager(self): for n in range(1, 4): tps = [ Transport(worker_class=Worker, adapter_class=ListAdapter) \ for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) with g: assert_group_running(g, tps) assert_group_stopped(g, tps)
def test_emit_autostart(self): for n in range(1, 4): tps = [ Transport(worker_class=Worker, adapter_class=ListAdapter) \ for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) assert_group_emit(g, tps) g.stop() assert_group_stopped(g, tps)
def temitter(**kwargs): if not ('adapter' in kwargs): kwargs['adapter'] = ListAdapter() if not ('transport' in kwargs): if not ('worker_class' in kwargs): kwargs['worker_class'] = Worker kwargs['transport'] = Transport( kwargs['adapter'], worker_class=kwargs['worker_class']) del kwargs['adapter'] del kwargs['worker_class'] if not ('event_stack' in kwargs): kwargs['event_stack'] = tevent_stack() return Emitter(**kwargs)
def test_halt_when_transport_worker_is_none(self): for n in range(1, 4): tps = [Transport() for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.start() assert_group_running(g, tps) for tp in tps: tp.worker = None g.halt() assert_group_stopped(g, tps)
def test_stop_when_transport_stopped(self): for n in range(1, 4): tps = [Transport() for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.start() assert_group_running(g, tps) for tp in tps: tp.stop() g.stop() assert_group_stopped(g, tps)
def test_running(self): # test multiple transport counts for n in range(1, 4): tps = [Transport() for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.start() assert_group_running(g, tps) g.start() # multiple calls to start are okay assert_group_running(g, tps) g.stop() # multiple calls to stop are okay assert_group_stopped(g, tps)
def test__init__kwargs_assigned(self): cases = { 'adapter_class': self.TAdapter, 'worker_class': self.TWorker, 'queue_class': self.TQueue, 'max_queue_size': timedelta(1), 'max_flush_time': timedelta(2), 'max_work_time': timedelta(3), 'max_stopping_time': timedelta(4)} for case in cases: kwargs = dict() kwargs[case] = cases[case] t = Transport(**kwargs) assert_transport(t) assert getattr(t, case) == cases[case]
def test_emit_underlying_stopped(self): for n in range(1, 4): tps = [ Transport(worker_class=Worker, adapter_class=ListAdapter) \ for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) assert_group_emit(g, tps) assert_group_running(g, tps) assert all(tp.running for tp in tps) assert g.running, 'should be running' for tp in tps: tp.stop() assert all(not tp.running for tp in tps) assert not g.running, 'should be stopped'
def test_halt_group_doesnt_do_work(self): for n in range(1, 4): tps = [Transport(worker_class=Worker) for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.start() assert_group_running(g, tps) for tp in tps: expect_json = tjson() tp.queue.put(expect_json, True, None) assert len(tp.queue) == 1 g.halt() assert_group_stopped(g, tps) for tp in tps: assert len(tp.queue) == 1, 'exp no work on call to halt'
def test_emit_flush(self): for n in range(1, 4): tps = [ Transport(worker_class=Worker, adapter_class=ListAdapter) \ for i in range(n)] g = Group(*tps) assert_group_stopped(g, tps) g.start() assert_group_running(g, tps) for tp in tps: expect_json = tjson() tp.queue.put(expect_json, True, None) assert len(tp.queue) == 1 g.flush() for tp in tps: assert len(tp.queue) == 0, 'exp empty queue after flush'
def test__init__kwargs_worker_class(self): t = Transport(worker_class=self.TWorker) assert_transport(t) t.start() assert isinstance(t.worker, self.TWorker)
def test__init__(self): tps = [Transport(), Transport(), Transport()] g = Group(*tps) assert_group_stopped(g, tps)
def test__init__(self): t = Transport() assert_transport(t) assert t.worker is None
def test__init__kwargs_queue_class(self): t = Transport(queue_class=self.TQueue) assert_transport(t) assert isinstance(t.queue, self.TQueue)
def test__init__kwargs_queue(self): queue = self.TQueue() t = Transport(queue=queue) assert_transport(t) assert t.queue == queue
def test__init__kwargs_worker(self): sentinel = object() t = Transport(worker=sentinel) assert_transport(t) assert t.worker == sentinel
def test__init__kwargs_adapter_class(self): adapter_class = self.TAdapter t = Transport(adapter_class=adapter_class) assert_transport(t) assert isinstance(t.adapter, adapter_class)
def test__init__kwargs_adapter(self): adapter = self.TAdapter() t = Transport(adapter=adapter) assert_transport(t) assert t.adapter == adapter