Abstract vprint; vprint the interaction as matched

This commit is contained in:
Jason Rhinelander 2023-04-28 18:53:43 -03:00
parent 45cbd97f07
commit 68e2fc1a56
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
4 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,7 @@
import re
import time
from concurrent.futures import ThreadPoolExecutor
from vprint import vprint
executor = ThreadPoolExecutor(max_workers=1)
@ -155,6 +156,7 @@ def run_with_interactions(ledger, main, *interactions, timeout=30, poll=0.25):
for f in interactions:
while time.time() < timeout_at and not future.done():
if f(ledger):
vprint(f"Interaction success: {f.desc if hasattr(f, 'desc') else f}")
break
time.sleep(poll)
else:

1
tests/ledger/vprint.py Symbolic link
View File

@ -0,0 +1 @@
../network_tests/vprint.py

View File

@ -17,9 +17,10 @@
from daemons import Daemon, Wallet
import vprint as v
from vprint import vprint
import random
import time
from datetime import datetime
import uuid
import pytest
@ -47,17 +48,6 @@ def wait_for(callback, timeout=10):
time.sleep(0.25)
verbose = False
def vprint(*args, timestamp=True, **kwargs):
global verbose
if verbose:
if timestamp:
print(datetime.now(), end=" ")
print(*args, **kwargs)
class SNNetwork:
def __init__(self, datadir, *, binpath, sns=20, nodes=3):
self.datadir = datadir
@ -256,8 +246,7 @@ class SNNetwork:
def print_wallet_balances(self):
"""Instructs the wallets to refresh and prints their balances (does nothing in non-verbose mode)"""
global verbose
if not verbose:
if not v.verbose:
return
vprint("Balances:")
for w in self.wallets:
@ -284,10 +273,10 @@ def sn_net(pytestconfig, tmp_path, binary_dir):
it loads it starts the daemons and wallets, mines a bunch of blocks and submits SN
registrations. On subsequent loads it mines 5 blocks so that mike always has some available
funds, and resets alice and bob to new wallets."""
global snn, verbose
global snn
if not snn:
verbose = pytestconfig.getoption("verbose") >= 2
if verbose:
v.verbose = pytestconfig.getoption("verbose") >= 2
if v.verbose:
print("\nConstructing initial service node network")
snn = SNNetwork(datadir=tmp_path, binpath=binary_dir)
else:
@ -314,10 +303,10 @@ def basic_net(pytestconfig, tmp_path, binary_dir):
wallets, mines a bunch of blocks and submits the SN registration. On subsequent loads it mines
5 blocks so that mike always has some available funds, and resets alice and bob to new
wallets."""
global snn, verbose
global snn
if not snn:
verbose = pytestconfig.getoption("verbose") >= 2
if verbose:
v.verbose = pytestconfig.getoption("verbose") >= 2
if v.verbose:
print("\nConstructing initial node network")
snn = SNNetwork(datadir=tmp_path, binpath=binary_dir, sns=1, nodes=1)
else:

View File

@ -0,0 +1,12 @@
from datetime import datetime
verbose = False
def vprint(*args, timestamp=True, **kwargs):
global verbose
if verbose:
if timestamp:
print(datetime.now(), end=" ")
print(*args, **kwargs)