Skip to content

Commit b2a2d9e

Browse files
committed
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.
1 parent 71521d1 commit b2a2d9e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ jobs:
250250
# remove old files so we can rerun in-place with "act -r" during test development
251251
rm -vf ~/.ssh/id_dropbear*
252252
~/inst/bin/dropbearkey -t ecdsa -f ~/.ssh/id_dropbear | grep ^ecdsa > ~/.ssh/authorized_keys
253+
# Convert to openssh format so that asyncssh can find it in tests
254+
~/inst/bin/dropbearconvert dropbear openssh ~/.ssh/id_dropbear ~/.ssh/id_ecdsa
253255
254256
# to test setting SSH_PUBKEYINFO, replace the trailing comment
255257
~/inst/bin/dropbearkey -t ecdsa -f ~/.ssh/id_dropbear_key2 | grep ^ecdsa | sed 's/[^ ]*$/key2 extra/' >> ~/.ssh/authorized_keys

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ psutil==6.0.0
66
pyparsing==2.4.7
77
pytest==8.3.2
88
toml==0.10.2
9+
asyncssh==2.17.0

test/test_concurrent.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Tests opening and closing several (up to 4) channels concurrently.
3+
"""
4+
from test_dropbear import *
5+
6+
import asyncssh
7+
import asyncio
8+
import random
9+
10+
async def run(addr, port):
11+
async with asyncssh.connect(addr, port = port) as conn:
12+
13+
chans = []
14+
MAX=4
15+
16+
for x in range(10000):
17+
if len(chans) < MAX:
18+
pipes = await conn.open_session(command = "df")
19+
chans.append(pipes)
20+
l = len(chans)
21+
print(f" add, len {l}")
22+
23+
if random.random() < 0.2:
24+
i = random.randrange(0, len(chans))
25+
l = len(chans)
26+
print(f" del {i}/{l}")
27+
del chans[i]
28+
29+
def test_concurrent(request, dropbear):
30+
opt = request.config.option
31+
host = opt.remote or LOCALADDR
32+
port = int(opt.port)
33+
34+
asyncio.run(run(host, port))

0 commit comments

Comments
 (0)