Skip to content
Permalink
Browse files

test/test_crossbar: test error handling for connection errors or time…

…outs

We can simulate a stalled coordinator by sending SIGSTOP to all it's
processes.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe committed Nov 29, 2019
1 parent 0fb1b9d commit 66b6d0b5698e923ebf80813d1a139d187054c1d9
Showing with 33 additions and 0 deletions.
  1. +1 −0 dev-requirements.txt
  2. +32 −0 tests/test_crossbar.py
@@ -4,6 +4,7 @@ pytest-mock==1.12.1
pytest-pylint==0.14.1
pytest-dependency==0.4.0
yapf==0.28.0
psutil==5.6.3
-r doc-requirements.txt
-r crossbar-requirements.txt
-r onewire-requirements.txt
@@ -5,10 +5,23 @@

import pytest
import pexpect
import psutil

pytestmark = pytest.mark.skipif(not find_spec("crossbar"),
reason="crossbar required")

def suspend_tree(pid):
main = psutil.Process(pid)
main.suspend()
for child in main.children(recursive=True):
child.suspend()

def resume_tree(pid):
main = psutil.Process(pid)
main.resume()
for child in main.children(recursive=True):
child.resume()

def test_startup(crossbar):
pass

@@ -50,6 +63,25 @@ def place_acquire(place, exporter):
spawn.close()
assert spawn.exitstatus == 0, spawn.before.strip()

def test_connect_error():
with pexpect.spawn('python -m labgrid.remote.client -x ws://127.0.0.1:20409/ws places') as spawn:
spawn.expect("Could not connect to coordinator")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 1, spawn.before.strip()

def test_connect_timeout(crossbar):
suspend_tree(crossbar.pid)
try:
with pexpect.spawn('python -m labgrid.remote.client places') as spawn:
spawn.expect("connection closed during setup")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 1, spawn.before.strip()
finally:
resume_tree(crossbar.pid)
pass

def test_place_show(place):
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn:
spawn.expect("Place 'test':")

0 comments on commit 66b6d0b

Please sign in to comment.
You can’t perform that action at this time.