Пример #1
0
 def test_exception_on_invalid_dependency(self):
     services = [
         Bunch(name="hello", image="hello", dependencies=[]),
         Bunch(name="goodbye", image="goodbye", dependencies=["not_hello"])
     ]
     with pytest.raises(ServiceLoadError):
         connect_services(services)
Пример #2
0
 def test_raise_exception_on_same_name(self):
     services = [
         Bunch(name="hello", image="hello"),
         Bunch(name="hello", image="goodbye")
     ]
     with pytest.raises(ServiceLoadError):
         connect_services(services)
Пример #3
0
 def test_service_started_lock_call(self, mock_threading):
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=['service1'])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     context.service_started(services['service1'])
     mock_lock = mock_threading.Lock.return_value
     assert mock_lock.__enter__.call_count == 1
Пример #4
0
 def test_fail_dependencies(self):
     """If a service fails to start, all the other services that depend on it are
     also registered as failed"""
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=['service1'])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     context.service_failed(services['service1'])
     assert len(context.failed_services) == 2
Пример #5
0
 def test_ready_to_start_and_stop(self):
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=['service1'])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     assert len(context.ready_to_start) == 1
     assert context.ready_to_start[0].service == services['service1']
     assert len(context.ready_to_stop) == 1
     assert context.ready_to_stop[0].service == services['service2']
Пример #6
0
 def test_can_stop(self):
     services = connect_services([
         Bunch(name='service1', dependencies=[]),
         Bunch(name='service2', dependencies=['service1'])
     ])
     agent = ServiceAgent(services['service1'], DEFAULT_OPTIONS, None)
     assert agent.can_stop is False
     agent.process_service_stopped(services['service2'])
     assert agent.can_stop is True
Пример #7
0
 def test_service_failed_lock_call(self, mock_threading):
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=['service1'])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     context.service_failed(services['service1'])
     mock_lock = mock_threading.Lock.return_value
     # This has to be 2 because service1 has a dependency, and it has to be
     # locked as well
     assert mock_lock.__enter__.call_count == 2
Пример #8
0
 def test_done_on_fail(self):
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=[])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     assert not context.done
     context.service_started(services['service1'])
     assert not context.done
     context.service_failed(services['service2'])
     assert context.done
Пример #9
0
 def test_service_stopped(self):
     services = connect_services([FakeService(name='service1', dependencies=[]),
                                  FakeService(name='service2', dependencies=['service1'])])
     context = RunningContext(services, DEFAULT_OPTIONS)
     context.service_stopped(services['service2'])
     assert len(context.agent_set) == 1
     assert len(context.processed_services) == 1
     assert context.processed_services[0] is services['service2']
     assert services['service1'] in context.agent_set
     assert context.agent_set[services['service1']].can_stop
Пример #10
0
 def test_can_start(self):
     services = connect_services([
         Bunch(name='service1', dependencies=[]),
         Bunch(name='service2', dependencies=['service1'])
     ])
     agent = ServiceAgent(services['service2'], DEFAULT_OPTIONS, None)
     assert agent.can_start is False
     agent.process_service_started(services['service1'])
     assert agent.can_start is True
     agent.status = AgentStatus.IN_PROGRESS
     assert agent.can_start is False
Пример #11
0
 def test_all_good(self):
     services = [
         Bunch(name="hello", image="hello", dependencies=[]),
         Bunch(name="goodbye", image="goodbye", dependencies=["hello"]),
         Bunch(name="howareyou",
               image="howareyou",
               dependencies=["hello", "goodbye"])
     ]
     by_name = connect_services(services)
     assert len(by_name) == 3
     hello = by_name['hello']
     assert hello.dependencies == []
     assert len(hello.dependants) == 2
     assert by_name['goodbye'] in hello.dependants
     assert by_name['howareyou'] in hello.dependants
     howareyou = by_name['howareyou']
     assert len(howareyou.dependencies) == 2
     assert hello in howareyou.dependencies
     assert by_name['goodbye'] in howareyou.dependencies
     assert howareyou.dependants == []