def test_crossover_bounce_no_existing_apps(self): """When marathon is unaware of a service, crossover bounce should try to create a marathon app.""" new_config = {'id': 'foo.bar.12345', 'instances': 5} happy_tasks = [] old_app_live_tasks = {} assert bounce_lib.crossover_bounce( new_config=new_config, new_app_running=False, happy_new_tasks=happy_tasks, old_app_live_tasks=old_app_live_tasks, ) == { "create_app": True, "tasks_to_drain": set(), }
def test_crossover_bounce_done(self): """When marathon has the desired app, and there are no other copies of the service running, crossover bounce should neither start nor stop anything.""" new_config = {'id': 'foo.bar.12345', 'instances': 5} happy_tasks = [mock.Mock() for _ in xrange(5)] old_app_live_tasks = {} assert bounce_lib.crossover_bounce( new_config=new_config, new_app_running=True, happy_new_tasks=happy_tasks, old_app_live_tasks=old_app_live_tasks, ) == { "create_app": False, "tasks_to_drain": set(), }
def test_crossover_bounce_mid_bounce(self): """When marathon has the desired app, and there are other copies of the service running, but the new app is not fully up, crossover bounce should only stop a few of the old instances.""" new_config = {'id': 'foo.bar.12345', 'instances': 5} happy_tasks = [mock.Mock() for _ in xrange(3)] old_app_live_tasks = { 'app1': set(mock.Mock() for _ in xrange(3)), 'app2': set(mock.Mock() for _ in xrange(2)), } actual = bounce_lib.crossover_bounce( new_config=new_config, new_app_running=True, happy_new_tasks=happy_tasks, old_app_live_tasks=old_app_live_tasks, ) assert actual['create_app'] is False assert len(actual['tasks_to_drain']) == 3
def test_crossover_bounce_old_but_no_new(self): """When marathon only has old apps for this service, crossover bounce should start the new one, but not kill any old tasks yet.""" new_config = {'id': 'foo.bar.12345', 'instances': 5} happy_tasks = [] old_app_live_tasks = { 'app1': set(mock.Mock() for _ in xrange(3)), 'app2': set(mock.Mock() for _ in xrange(2)), } assert bounce_lib.crossover_bounce( new_config=new_config, new_app_running=False, happy_new_tasks=happy_tasks, old_app_live_tasks=old_app_live_tasks, ) == { "create_app": True, "tasks_to_drain": set(), }
def test_crossover_bounce_cleanup(self): """When marathon has the desired app, and there are other copies of the service running, which have no remaining tasks, those apps should be killed.""" new_config = {'id': 'foo.bar.12345', 'instances': 5} happy_tasks = [mock.Mock() for _ in xrange(5)] old_app_live_tasks = { 'app1': set(), 'app2': set(), } assert bounce_lib.crossover_bounce( new_config=new_config, new_app_running=True, happy_new_tasks=happy_tasks, old_app_live_tasks=old_app_live_tasks, ) == { "create_app": False, "tasks_to_drain": set(), }