Commit ca4af748 authored by Kirill Smelkov's avatar Kirill Smelkov

os/signal: tests: use raise instead of kill(self)

Because on Windows os.kill unconditionally terminates target process,
even if own self, instead of sending it any kind of signal.
parent 75d40910
...@@ -30,6 +30,11 @@ from golang.golang_test import panics, _pyrun ...@@ -30,6 +30,11 @@ from golang.golang_test import panics, _pyrun
from pytest import raises from pytest import raises
from subprocess import PIPE from subprocess import PIPE
try:
from signal import raise_signal
except ImportError: # py2
from _testcapi import raise_signal
# directories # directories
dir_os = dirname(__file__) # .../pygolang/os dir_os = dirname(__file__) # .../pygolang/os
...@@ -363,8 +368,9 @@ def test_stdlib_interop_KeyboardInterrupt(): ...@@ -363,8 +368,9 @@ def test_stdlib_interop_KeyboardInterrupt():
# killme sends signal sig to own process. # killme sends signal sig to own process.
def killme(sig): def killme(sig):
mypid = os.getpid() # use raise(sig) instead of kill(mypid, sig) so that it works on windows,
os.kill(mypid, sig.signo) # where os.kill unconditionally terminates target process.
raise_signal(sig.signo)
# wait for waits until cond() becomes true or timeout. # wait for waits until cond() becomes true or timeout.
def waitfor(cond): def waitfor(cond):
......
#!/usr/bin/env python #!/usr/bin/env python
# Copyright (C) 2021-2022 Nexedi SA and Contributors. # Copyright (C) 2021-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -24,7 +24,8 @@ from __future__ import print_function, absolute_import ...@@ -24,7 +24,8 @@ from __future__ import print_function, absolute_import
from golang import chan from golang import chan
from golang import os as gos, syscall, time from golang import os as gos, syscall, time
from golang.os import signal from golang.os import signal
import os, sys from golang.os.signal_test import killme
import sys
def main(): def main():
# build "all signals" list # build "all signals" list
...@@ -72,11 +73,6 @@ def main(): ...@@ -72,11 +73,6 @@ def main():
killme(syscall.SIGTERM) killme(syscall.SIGTERM)
raise AssertionError("not terminated") raise AssertionError("not terminated")
# killme sends signal sig to own process.
def killme(sig):
mypid = os.getpid()
os.kill(mypid, sig.signo)
def emit(msg=''): def emit(msg=''):
print(msg) print(msg)
sys.stdout.flush() sys.stdout.flush()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment