b_config_1.experimental_graceful_shutdown_timeout_s = grace_period_s
// Create and delete the backend.
tag = "tag"
backend_state.deploy_backend(tag, b_config_1, r_config_1)
backend_state.update()
backend_state._replicas[tag].get()[0]._actor.set_ready()
backend_state.update()
delete_goal = backend_state.delete_backend(tag)
backend_state.update()
After Change
backend_state.update()
// Replica should remain in STOPPING until it finishes.
check_counts(backend_state, total=1, by_state=[(ReplicaState.STOPPING, 1)])
assert backend_state._replicas[TEST_TAG].get()[0]._actor.stopped
backend_state.update()
backend_state.update()
// force_stop shouldn"t be called until after the timer.
assert not backend_state._replicas[TEST_TAG].get(
)[0]._actor.force_stopped_counter
assert not backend_state._replicas[TEST_TAG].get()[0]._actor.cleaned_up
check_counts(backend_state, total=1, by_state=[(ReplicaState.STOPPING, 1)])
// Advance the timer, now the replica should be force stopped.
timer.advance(grace_period_s + 0.1)
backend_state.update()
assert backend_state._replicas[TEST_TAG].get()[
0]._actor.force_stopped_counter == 1
assert not backend_state._replicas[TEST_TAG].get()[0]._actor.cleaned_up
check_counts(backend_state, total=1, by_state=[(ReplicaState.STOPPING, 1)])
assert not goal_manager.check_complete(delete_goal)
// Force stop should be called repeatedly until the replica stops.
backend_state.update()
assert backend_state._replicas[TEST_TAG].get()[
0]._actor.force_stopped_counter == 2
assert not backend_state._replicas[TEST_TAG].get()[0]._actor.cleaned_up
check_counts(backend_state, total=1, by_state=[(ReplicaState.STOPPING, 1)])
assert not goal_manager.check_complete(delete_goal)
// Once the replica is done stopping, it should be removed.
replica = backend_state._replicas[TEST_TAG].get()[0]