def test_killWorker_spawns_another(self): service = WorkersService(reactor, worker_count=1, worker_cmd="cat") dv = DeferredValue() original_unregisterWorker = service.unregisterWorker def mock_unregisterWorker(*args, **kwargs): original_unregisterWorker(*args, **kwargs) dv.set(None) self.patch( service, "unregisterWorker" ).side_effect = mock_unregisterWorker try: service.startService() self.assertEquals(1, len(service.workers)) pid = list(service.workers.keys())[0] service.killWorker(pid) yield dv.get(timeout=2) self.assertNotIn(pid, service.workers) self.assertEquals(1, len(service.workers)) finally: service.stopService()
def test_stopService_doesnt(self): service = WorkersService(reactor, worker_count=1, worker_cmd="cat") dv = DeferredValue() original_unregisterWorker = service.unregisterWorker def mock_unregisterWorker(*args, **kwargs): original_unregisterWorker(*args, **kwargs) dv.set(None) self.patch(service, "unregisterWorker").side_effect = mock_unregisterWorker try: service.startService() self.assertEqual(1, len(service.workers)) finally: service.stopService() yield dv.get(timeout=2) self.assertEqual({}, service.workers)