Merge #20613: test: Use Popen.wait instead of RPC in assert_start_raises_init_error

fa918dd537fea775c19a590e5f9161bf51a5839b test: Use Popen.wait instead of RPC in assert_start_raises_init_error (MarcoFalke)

Pull request description:

  Using RPC (`wait_for_rpc_connection`) has several issue:

  * It polls in a loop, which might be slow
  * It tries to read the RPC cookie file, which might not be present, thus leading to intermittent issues

  Fix both by using `Popen.wait`

ACKs for top commit:
  laanwj:
    Code review ACK ~~faf7b05be9c86ee61c39e5314511fe2410128a6b~~ fa918dd537fea775c19a590e5f9161bf51a5839b
  darosior:
    ACK fa918dd537fea775c19a590e5f9161bf51a5839b

Tree-SHA512: 5368ad0d0ea2deb0af9582a42667c9290efe8f2705f37a236afc2c7908b04265ab342e2dd356a57156e99389f4a27ab6da9fa7bf9161fb7568240aa005e693b9
This commit is contained in:
MarcoFalke 2020-12-10 18:37:50 +01:00 committed by PastaPastaPasta
parent 666fa51a7c
commit 9a3abd973c

View File

@ -490,11 +490,8 @@ class TestNode():
tempfile.NamedTemporaryFile(dir=self.stdout_dir, delete=False) as log_stdout: tempfile.NamedTemporaryFile(dir=self.stdout_dir, delete=False) as log_stdout:
try: try:
self.start(extra_args, stdout=log_stdout, stderr=log_stderr, *args, **kwargs) self.start(extra_args, stdout=log_stdout, stderr=log_stderr, *args, **kwargs)
self.wait_for_rpc_connection() ret = self.process.wait(timeout=self.rpc_timeout)
self.stop_node() self.log.debug(self._node_msg(f'dashd exited with status {ret} during initialization'))
self.wait_until_stopped()
except FailedToStartError as e:
self.log.debug('dashd failed to start: %s', e)
self.running = False self.running = False
self.process = None self.process = None
# Check stderr for expected message # Check stderr for expected message
@ -513,11 +510,15 @@ class TestNode():
if expected_msg != stderr: if expected_msg != stderr:
self._raise_assertion_error( self._raise_assertion_error(
'Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr)) 'Expected message "{}" does not fully match stderr:\n"{}"'.format(expected_msg, stderr))
else: except subprocess.TimeoutExpired:
self.process.kill()
self.running = False
self.process = None
assert_msg = f'dashd should have exited within {self.rpc_timeout}s '
if expected_msg is None: if expected_msg is None:
assert_msg = "dashd should have exited with an error" assert_msg += "with an error"
else: else:
assert_msg = "dashd should have exited with expected error " + expected_msg assert_msg += "with expected error " + expected_msg
self._raise_assertion_error(assert_msg) self._raise_assertion_error(assert_msg)
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs): def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):