Skip to content

Commit ad87e50

Browse files
committed
move concurrency_limit to identify_push
Signed-off-by: sukhman <[email protected]>
1 parent 644fc77 commit ad87e50

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libp2p/identity/identify_push/identify_push.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
ID_PUSH = TProtocol("/ipfs/id/push/1.0.0")
4141
PROTOCOL_VERSION = "ipfs/0.1.0"
4242
AGENT_VERSION = get_agent_version()
43-
LIMIT = trio.Semaphore(10)
43+
CONCURRENCY_LIMIT = 10
44+
LIMIT = trio.Semaphore(CONCURRENCY_LIMIT)
4445

4546

4647
def identify_push_handler_for(host: IHost) -> StreamHandlerFn:

tests/core/identity/identify_push/test_identify_push.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Identify,
2121
)
2222
from libp2p.identity.identify_push.identify_push import (
23+
CONCURRENCY_LIMIT,
2324
ID_PUSH,
2425
_update_peerstore_from_identify,
2526
identify_push_handler_for,
@@ -449,16 +450,14 @@ async def test_push_identify_to_peers_respects_concurrency_limit():
449450
It mocks `push_identify_to_peer` to simulate delay using sleep,
450451
allowing the test to measure and assert actual concurrency behavior.
451452
"""
452-
CONCURRENCY_LIMIT = 10
453-
LIMIT = trio.Semaphore(CONCURRENCY_LIMIT)
454453
state = {
455454
"concurrency_counter": 0,
456455
"max_observed": 0,
457456
}
458457
lock = trio.Lock()
459458

460459
async def mock_push_identify_to_peer(
461-
host, peer_id, observed_multiaddr=None
460+
host, peer_id, observed_multiaddr=None, limit=trio.Semaphore(CONCURRENCY_LIMIT)
462461
) -> bool:
463462
"""
464463
Mock function to test concurrency by simulating an identify message.
@@ -471,7 +470,7 @@ async def mock_push_identify_to_peer(
471470
True if the push was successful, False otherwise.
472471
473472
"""
474-
async with LIMIT:
473+
async with limit:
475474
async with lock:
476475
state["concurrency_counter"] += 1
477476
if state["concurrency_counter"] > CONCURRENCY_LIMIT:

0 commit comments

Comments
 (0)