tests: Intercept signals in test_scripts.py

This commit is contained in:
tecnovert 2025-01-30 15:56:25 +02:00
parent a0456cb689
commit 831ef40977
No known key found for this signature in database
GPG key ID: 8ED6D8750C4E3F93
8 changed files with 69 additions and 57 deletions

View file

@ -6,15 +6,15 @@
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import os
import sys
import json import json
import logging
import multiprocessing
import os
import shutil import shutil
import signal import signal
import logging import sys
import unittest
import threading import threading
import multiprocessing import unittest
from io import StringIO from io import StringIO
from urllib.request import urlopen from urllib.request import urlopen
from unittest.mock import patch from unittest.mock import patch
@ -534,7 +534,7 @@ class TestBase(unittest.TestCase):
) )
def signal_handler(self, sig, frame): def signal_handler(self, sig, frame):
logging.info("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
self.delay_event.set() self.delay_event.set()
def wait_seconds(self, seconds): def wait_seconds(self, seconds):

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2022-2023 tecnovert # Copyright (c) 2022-2023 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -11,16 +11,16 @@ basicswap]$ python tests/basicswap/extended/test_dash.py
""" """
import os
import sys
import json import json
import time import logging
import os
import random import random
import shutil import shutil
import signal import signal
import logging import sys
import unittest
import threading import threading
import time
import unittest
import basicswap.config as cfg import basicswap.config as cfg
from basicswap.basicswap import ( from basicswap.basicswap import (
@ -251,7 +251,7 @@ def dashRpc(cmd, wallet=None):
def signal_handler(sig, frame): def signal_handler(sig, frame):
global stop_test global stop_test
print("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
stop_test = True stop_test = True
delay_event.set() delay_event.set()

View file

@ -2,19 +2,20 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 tecnovert # Copyright (c) 2020-2021 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import os
import json import json
import time import logging
import os
import shutil import shutil
import signal import signal
import logging import sys
import unittest
import threading import threading
import time
import traceback import traceback
import unittest
import basicswap.config as cfg import basicswap.config as cfg
from basicswap.basicswap import ( from basicswap.basicswap import (
@ -150,7 +151,7 @@ def btcRpc(cmd, node_id=0):
def signal_handler(sig, frame): def signal_handler(sig, frame):
global stop_test global stop_test
logging.info("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
stop_test = True stop_test = True
delay_event.set() delay_event.set()

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2019-2021 tecnovert # Copyright (c) 2019-2021 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -11,15 +11,15 @@ basicswap]$ python tests/basicswap/extended/test_nmc.py
""" """
import os
import sys
import json import json
import time import logging
import os
import shutil import shutil
import signal import signal
import logging import sys
import unittest
import threading import threading
import time
import unittest
import basicswap.config as cfg import basicswap.config as cfg
from basicswap.basicswap import ( from basicswap.basicswap import (
@ -231,7 +231,7 @@ def nmcRpc(cmd):
def signal_handler(sig, frame): def signal_handler(sig, frame):
global stop_test global stop_test
print("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
stop_test = True stop_test = True
delay_event.set() delay_event.set()

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2022-2023 tecnovert # Copyright (c) 2022-2023 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -11,16 +11,16 @@ basicswap]$ python tests/basicswap/extended/test_pivx.py
""" """
import os
import sys
import json import json
import time import logging
import os
import random import random
import shutil import shutil
import signal import signal
import logging import sys
import unittest
import threading import threading
import time
import unittest
import basicswap.config as cfg import basicswap.config as cfg
from basicswap.basicswap import ( from basicswap.basicswap import (
@ -256,7 +256,7 @@ def pivxRpc(cmd):
def signal_handler(sig, frame): def signal_handler(sig, frame):
global stop_test global stop_test
print("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
stop_test = True stop_test = True
delay_event.set() delay_event.set()

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2023-2024 tecnovert # Copyright (c) 2023-2024 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -15,17 +15,18 @@ pytest -v -s tests/basicswap/extended/test_scripts.py::Test::test_bid_tracking
""" """
import os
import sys
import json
import time
import math
import logging
import sqlite3
import unittest
import threading
import subprocess
import http.client import http.client
import json
import logging
import math
import os
import signal
import sqlite3
import subprocess
import sys
import threading
import time
import unittest
from http.server import BaseHTTPRequestHandler, HTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib import parse from urllib import parse
@ -196,6 +197,11 @@ def get_possible_bids(rv_stdout):
return bids return bids
def signal_handler(self, sig, frame):
os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
self.delay_event.set()
class Test(unittest.TestCase): class Test(unittest.TestCase):
delay_event = threading.Event() delay_event = threading.Event()
thread_http = HttpThread() thread_http = HttpThread()
@ -203,6 +209,11 @@ class Test(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(Test, cls).setUpClass() super(Test, cls).setUpClass()
signal.signal(
signal.SIGINT, lambda signal, frame: signal_handler(cls, signal, frame)
)
cls.thread_http.start() cls.thread_http.start()
script_path = "scripts/createoffers.py" script_path = "scripts/createoffers.py"

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (c) 2021-2024 tecnovert # Copyright (c) 2021-2024 tecnovert
# Copyright (c) 2024 The Basicswap developers # Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
@ -22,16 +22,16 @@ cp -r ${TEST_PATH}/bin/ ~/tmp/basicswap_bin/
""" """
import os
import sys
import json import json
import time import logging
import multiprocessing
import os
import random import random
import signal import signal
import logging import sys
import unittest
import threading import threading
import multiprocessing import time
import unittest
from unittest.mock import patch from unittest.mock import patch
from basicswap.rpc_xmr import ( from basicswap.rpc_xmr import (
@ -219,7 +219,7 @@ def updateThreadDCR(cls):
def signal_handler(self, sig, frame): def signal_handler(self, sig, frame):
logging.info("signal {} detected.".format(sig)) os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8"))
self.delay_event.set() self.delay_event.set()

View file

@ -6,16 +6,16 @@
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
import os
import json import json
import time import logging
import os
import random import random
import shutil import shutil
import signal import signal
import logging
import unittest
import traceback
import threading import threading
import time
import traceback
import unittest
import basicswap.config as cfg import basicswap.config as cfg
from basicswap.db import ( from basicswap.db import (