-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use python to rewrite process testing shell script. (#24)
Signed-off-by: Hongli Chen <[email protected]>
- Loading branch information
1 parent
dd77eaa
commit 9020022
Showing
7 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
test/openjd/adaptor_runtime/integ/process/scripts/echo_sleep_n_times.py
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,17 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import sys | ||
import time | ||
|
||
|
||
def repeat_message(message, count): | ||
for _ in range(count): | ||
print(message) | ||
print(message, file=sys.stderr) | ||
time.sleep(0.01) | ||
|
||
|
||
if __name__ == "__main__": | ||
message = sys.argv[1] | ||
num_times = int(sys.argv[2]) | ||
repeat_message(message, num_times) |
10 changes: 0 additions & 10 deletions
10
test/openjd/adaptor_runtime/integ/process/scripts/echo_sleep_n_times.sh
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
test/openjd/adaptor_runtime/integ/process/scripts/no_sigterm.sh
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
test/openjd/adaptor_runtime/integ/process/scripts/print_signals.sh
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
test/openjd/adaptor_runtime/integ/process/scripts/signals_test.py
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,39 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
import signal | ||
import sys | ||
import time | ||
from datetime import datetime | ||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def flush_logging(): | ||
for handler in logger.handlers: | ||
handler.flush() | ||
|
||
|
||
def func_trap(signum, frame): | ||
logger.info(f"Trapped: {signal.Signals(signum).name}") | ||
flush_logging() | ||
if exit_after_signal: | ||
exit(0) | ||
|
||
|
||
def set_signal_handlers(): | ||
signals = [signal.SIGTERM, signal.SIGINT] | ||
for sig in signals: | ||
signal.signal(sig, func_trap) | ||
|
||
|
||
if __name__ == "__main__": | ||
exit_after_signal = sys.argv[1] == "True" | ||
logger.info("Starting signals_test.py Script") | ||
flush_logging() | ||
set_signal_handlers() | ||
|
||
while True: | ||
logger.info(datetime.now().strftime("%Y-%m-%d_%H:%M:%S")) | ||
time.sleep(1) |
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
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