Skip to content

Commit

Permalink
fix: locks
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jul 15, 2024
1 parent da40ec1 commit d0d278e
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/pytest_plugins/test_executer/senders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@ class SenderLock:
"""

sender: EOA
_lock: Lock = Lock()
_lock: Lock

def __init__(self, sender: EOA):
"""
Initialize the sender with a lock
"""
self.sender = sender

def acquire(self, *args, **kwargs):
"""
Acquire the locked.
"""
self._lock.acquire(*args, **kwargs)

def release(self, *args, **kwargs):
"""
Release the lock.
"""
self._lock.release(*args, **kwargs)
self._lock = Lock()


class Senders:
Expand Down Expand Up @@ -65,9 +54,9 @@ def get_sender(self) -> Generator[EOA, None, None]:
"""
while True:
for sender in self.senders:
if sender.acquire(blocking=False):
if sender._lock.acquire(blocking=False):
yield sender.sender
sender.release()
sender._lock.release()
return
time.sleep(0)

Expand Down Expand Up @@ -106,7 +95,6 @@ def sender_keys(
"""
sender_key_count = request.config.getoption("sender_key_count")
senders = Senders([next(eoa_iterator) for _ in range(sender_key_count)])
print(f"Sender keys: {[sender.sender for sender in senders]}")
# fund all sender keys
sender_key_initial_balance = request.config.getoption("sender_key_initial_balance")
for sender in senders:
Expand All @@ -116,5 +104,4 @@ def sender_keys(
value=sender_key_initial_balance,
).with_signature_and_sender()
eth_rpc.send_transaction(fund_tx)
print(f"Sender keys funded with {sender_key_initial_balance} wei")
return senders

0 comments on commit d0d278e

Please sign in to comment.