From 698123afec87514c51f81fd7de6eac0446e008b2 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 4 Nov 2020 17:35:17 +0200 Subject: [PATCH 1/3] Make TestAPIShutdown much like TestProcessShutdown (this version should pass on Fedora) --- src/tests/test_api.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 1d8891a8..8cc63290 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -9,12 +9,14 @@ from .common import skip_python3 skip_python3() +import psutil + try: # nosec from xmlrpclib import ServerProxy, ProtocolError except ImportError: from xmlrpc.client import ServerProxy, ProtocolError -from .test_process import TestProcessProto, TestProcessShutdown +from .test_process import TestProcessProto class TestAPIProto(TestProcessProto): @@ -34,18 +36,16 @@ class TestAPIProto(TestProcessProto): time.sleep(1) -class TestAPIShutdown(TestAPIProto, TestProcessShutdown): +class TestAPIShutdown(TestAPIProto): """Separate test case for API command 'shutdown'""" def test_shutdown(self): """Shutdown the pybitmessage""" self.assertEqual(self.api.shutdown(), 'done') - for _ in range(5): - if not self.process.is_running(): - break - time.sleep(2) - else: + try: + self.process.wait(20) + except psutil.TimeoutExpired: self.fail( - '%s has not stopped in 10 sec' % ' '.join(self._process_cmd)) + '%s has not stopped in 20 sec' % ' '.join(self._process_cmd)) # TODO: uncovered API commands -- 2.45.1 From b83c3f42d28c7be3f908f234432af9000546f1be Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 28 May 2021 20:46:17 +0300 Subject: [PATCH 2/3] Rely on test_process for skipping python3; use six.moves for xmlrpc-related imports --- src/tests/test_api.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 8cc63290..8069d160 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -5,17 +5,11 @@ Tests using API. import base64 import json import time -from .common import skip_python3 -skip_python3() +from six.moves import xmlrpc_client # nosec import psutil -try: # nosec - from xmlrpclib import ServerProxy, ProtocolError -except ImportError: - from xmlrpc.client import ServerProxy, ProtocolError - from .test_process import TestProcessProto @@ -28,7 +22,7 @@ class TestAPIProto(TestProcessProto): """Setup XMLRPC proxy for pybitmessage API""" super(TestAPIProto, cls).setUpClass() cls.addresses = [] - cls.api = ServerProxy( + cls.api = xmlrpc_client.ServerProxy( "http://username:password@127.0.0.1:8442/") for _ in range(5): if cls._get_readline('.api_started'): @@ -72,8 +66,9 @@ class TestAPI(TestAPIProto): def test_user_password(self): """Trying to connect with wrong username/password""" - api_wrong = ServerProxy("http://test:wrong@127.0.0.1:8442/") - with self.assertRaises(ProtocolError): + api_wrong = xmlrpc_client.ServerProxy( + "http://test:wrong@127.0.0.1:8442/") + with self.assertRaises(xmlrpc_client.ProtocolError): api_wrong.clientStatus() def test_connection(self): -- 2.45.1 From f6cb3ad0161d71ddd0a0d80ca56d06d170a8810c Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 28 May 2021 21:15:03 +0300 Subject: [PATCH 3/3] Fix bug in test_send_broadcast() - using temporary msgid for lookups. Wait for final msgid. Maximum PoW wait time is 30 sec. --- src/tests/test_api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 8069d160..413075a6 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -276,6 +276,7 @@ class TestAPI(TestAPIProto): msg = base64.encodestring('test broadcast') ackdata = self.api.sendBroadcast( addr, base64.encodestring('test_subject'), msg) + try: int(ackdata, 16) status = self.api.getStatus(ackdata) @@ -283,6 +284,15 @@ class TestAPI(TestAPIProto): raise KeyError self.assertIn(status, ( 'doingbroadcastpow', 'broadcastqueued', 'broadcastsent')) + + start = time.time() + while status == 'doingbroadcastpow': + spent = int(time.time() - start) + if spent > 30: + self.fail('PoW is taking too much time: %ss' % spent) + time.sleep(1) # wait for PoW to get final msgid on next step + status = self.api.getStatus(ackdata) + # Find the message and its ID in sent for m in json.loads(self.api.getAllSentMessages())['sentMessages']: if m['ackData'] == ackdata: -- 2.45.1