-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Test for concurrent channel open/close
This reproduces the problem reported in github #321 asyncssh is used to drive the connection for this test.
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ psutil==6.0.0 | |
pyparsing==2.4.7 | ||
pytest==8.3.2 | ||
toml==0.10.2 | ||
asyncssh==2.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Tests opening and closing several (up to 4) channels concurrently. | ||
""" | ||
from test_dropbear import * | ||
|
||
import asyncssh | ||
import asyncio | ||
import random | ||
|
||
async def run(addr, port): | ||
async with asyncssh.connect(addr, port = port) as conn: | ||
|
||
chans = [] | ||
MAX=4 | ||
|
||
for x in range(10000): | ||
if len(chans) < MAX: | ||
pipes = await conn.open_session(command = "df") | ||
chans.append(pipes) | ||
l = len(chans) | ||
print(f" add, len {l}") | ||
|
||
if random.random() < 0.2: | ||
i = random.randrange(0, len(chans)) | ||
l = len(chans) | ||
print(f" del {i}/{l}") | ||
del chans[i] | ||
|
||
def test_concurrent(request, dropbear): | ||
opt = request.config.option | ||
host = opt.remote or LOCALADDR | ||
port = int(opt.port) | ||
|
||
asyncio.run(run(host, port)) |