This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from kube_janitor.shutdown import GracefulShutdown | ||
|
||
|
||
def test_graceful_shutdown(monkeypatch): | ||
handler = GracefulShutdown() | ||
assert not handler.safe_to_exit | ||
with handler.safe_exit(): | ||
assert handler.safe_to_exit | ||
|
||
assert not handler.shutdown_now | ||
# this would be called by SIGINT or SIGTERM | ||
handler.exit_gracefully(None, None) | ||
assert handler.shutdown_now | ||
|
||
mock_exit = MagicMock() | ||
monkeypatch.setattr('sys.exit', mock_exit) | ||
with handler.safe_exit(): | ||
handler.exit_gracefully(None, None) | ||
|
||
mock_exit.assert_called_once_with(0) |