Skip to content

Commit fac2e6a

Browse files
author
MarcoFalke
committed
test: Fail early on disconnect in mininode.wait_for_*
1 parent dbf4f3f commit fac2e6a

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

test/functional/test_framework/mininode.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,23 @@ def wait_for_disconnect(self, timeout=60):
363363

364364
def wait_for_tx(self, txid, timeout=60):
365365
def test_function():
366+
assert self.is_connected
366367
if not self.last_message.get('tx'):
367368
return False
368369
return self.last_message['tx'].tx.rehash() == txid
369370

370371
wait_until(test_function, timeout=timeout, lock=mininode_lock)
371372

372373
def wait_for_block(self, blockhash, timeout=60):
373-
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
374+
def test_function():
375+
assert self.is_connected
376+
return self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
377+
374378
wait_until(test_function, timeout=timeout, lock=mininode_lock)
375379

376380
def wait_for_header(self, blockhash, timeout=60):
377381
def test_function():
382+
assert self.is_connected
378383
last_headers = self.last_message.get('headers')
379384
if not last_headers:
380385
return False
@@ -389,7 +394,11 @@ def wait_for_getdata(self, timeout=60):
389394
value must be explicitly cleared before calling this method, or this will return
390395
immediately with success. TODO: change this method to take a hash value and only
391396
return true if the correct block/tx has been requested."""
392-
test_function = lambda: self.last_message.get("getdata")
397+
398+
def test_function():
399+
assert self.is_connected
400+
return self.last_message.get("getdata")
401+
393402
wait_until(test_function, timeout=timeout, lock=mininode_lock)
394403

395404
def wait_for_getheaders(self, timeout=60):
@@ -399,20 +408,30 @@ def wait_for_getheaders(self, timeout=60):
399408
value must be explicitly cleared before calling this method, or this will return
400409
immediately with success. TODO: change this method to take a hash value and only
401410
return true if the correct block header has been requested."""
402-
test_function = lambda: self.last_message.get("getheaders")
411+
412+
def test_function():
413+
assert self.is_connected
414+
return self.last_message.get("getheaders")
415+
403416
wait_until(test_function, timeout=timeout, lock=mininode_lock)
404417

405418
def wait_for_inv(self, expected_inv, timeout=60):
406419
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
407420
if len(expected_inv) > 1:
408421
raise NotImplementedError("wait_for_inv() will only verify the first inv object")
409-
test_function = lambda: self.last_message.get("inv") and \
422+
423+
def test_function():
424+
assert self.is_connected
425+
return self.last_message.get("inv") and \
410426
self.last_message["inv"].inv[0].type == expected_inv[0].type and \
411427
self.last_message["inv"].inv[0].hash == expected_inv[0].hash
428+
412429
wait_until(test_function, timeout=timeout, lock=mininode_lock)
413430

414431
def wait_for_verack(self, timeout=60):
415-
test_function = lambda: self.message_count["verack"]
432+
def test_function():
433+
return self.message_count["verack"]
434+
416435
wait_until(test_function, timeout=timeout, lock=mininode_lock)
417436

418437
# Message sending helper functions
@@ -424,7 +443,11 @@ def send_and_ping(self, message, timeout=60):
424443
# Sync up with the node
425444
def sync_with_ping(self, timeout=60):
426445
self.send_message(msg_ping(nonce=self.ping_counter))
427-
test_function = lambda: self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
446+
447+
def test_function():
448+
assert self.is_connected
449+
return self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
450+
428451
wait_until(test_function, timeout=timeout, lock=mininode_lock)
429452
self.ping_counter += 1
430453

0 commit comments

Comments
 (0)