Пример #1
0
def test_http_lifecycle_wrapper_without_lifecycle():
  mti_without_lifecycle = MesosTaskInstance()
  mti_without_http_lifecycle = MesosTaskInstance(lifecycle=LifecycleConfig())

  runner_mock = mock.create_autospec(ThermosTaskRunner)
  assert HttpLifecycleManager.wrap(runner_mock, mti_without_lifecycle, {}) is runner_mock
  assert HttpLifecycleManager.wrap(runner_mock, mti_without_http_lifecycle, {}) is runner_mock
Пример #2
0
def make_mocks(mesos_task_instance, portmap):
    # wrap it once health is available and validate the constructor is called as expected
    runner_mock = mock.create_autospec(ThermosTaskRunner)
    with mock.patch.object(HttpLifecycleManager, '__init__',
                           return_value=None) as wrapper_init:
        runner_wrapper = HttpLifecycleManager.wrap(runner_mock,
                                                   mesos_task_instance,
                                                   portmap)
        yield runner_mock, runner_wrapper, wrapper_init
Пример #3
0
def test_http_lifecycle_wraps_start_and_stop():
  mti = MesosTaskInstance(lifecycle=LifecycleConfig(http=HttpLifecycleConfig()))
  runner_mock = mock.create_autospec(ThermosTaskRunner)
  with mock.patch.object(HttpLifecycleManager, '_terminate_http', return_value=None) as http_mock:
    runner_wrapper = HttpLifecycleManager.wrap(runner_mock, mti, {'health': 31337})

    # ensure that start and stop are properly wrapped
    runner_wrapper.start(23.3)
    assert runner_mock.start.mock_calls == [mock.call(timeout=23.3)]

    # ensure that http teardown called when stopped
    runner_wrapper.stop(32.2)
    assert http_mock.mock_calls == [mock.call()]
    assert runner_mock.stop.mock_calls == [mock.call(timeout=32.2)]
Пример #4
0
def make_mocks(mesos_task_instance, portmap):
  # wrap it once health is available and validate the constructor is called as expected
  runner_mock = mock.create_autospec(ThermosTaskRunner)
  with mock.patch.object(HttpLifecycleManager, '__init__', return_value=None) as wrapper_init:
    runner_wrapper = HttpLifecycleManager.wrap(runner_mock, mesos_task_instance, portmap)
    yield runner_mock, runner_wrapper, wrapper_init