Skip to content

Commit

Permalink
test: Test for concurrent channel open/close
Browse files Browse the repository at this point in the history
This reproduces the problem reported in github #321

asyncssh is used to drive the connection for this test.
  • Loading branch information
mkj committed Oct 21, 2024
1 parent 71521d1 commit b2a2d9e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ jobs:
# remove old files so we can rerun in-place with "act -r" during test development
rm -vf ~/.ssh/id_dropbear*
~/inst/bin/dropbearkey -t ecdsa -f ~/.ssh/id_dropbear | grep ^ecdsa > ~/.ssh/authorized_keys
# Convert to openssh format so that asyncssh can find it in tests
~/inst/bin/dropbearconvert dropbear openssh ~/.ssh/id_dropbear ~/.ssh/id_ecdsa
# to test setting SSH_PUBKEYINFO, replace the trailing comment
~/inst/bin/dropbearkey -t ecdsa -f ~/.ssh/id_dropbear_key2 | grep ^ecdsa | sed 's/[^ ]*$/key2 extra/' >> ~/.ssh/authorized_keys
Expand Down
1 change: 1 addition & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ psutil==6.0.0
pyparsing==2.4.7
pytest==8.3.2
toml==0.10.2
asyncssh==2.17.0
34 changes: 34 additions & 0 deletions test/test_concurrent.py
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))

0 comments on commit b2a2d9e

Please sign in to comment.