def test_scenario(): uas, uac = agent.server(), agent.client() agents = [uas, uac] scen = agent.Scenario(agents) scen2 = agent.Scenario(agents) # verify contained agents assert list(scen.agents.values()) == agents == scen._agents assert scen.prepare() != agents # new copies # verify order agents = list(scen.agents.values()) assert uas is agents[0] assert uac is agents[1] # verify servers assert uas is list(scen.servers.values())[0] # verify clients assert uac is list(scen.clients.values())[0] # ensure defaults attr setting works doggy = "doggy" scen.local_host = doggy uas, uac = scen.prepare() assert uac.local_host == uas.local_host == doggy # should be no shared state between instances assert scen2.local_host != doggy scen2.local_host = 10 assert scen.local_host == doggy # same error for any non-spec defined agent attr with pytest.raises(AttributeError): scen.agentdefaults.local_man = "flasher" scen.prepare() # defaults on servers only scen.serverdefaults.uri_username = doggy uas, uac = scen.prepare() assert uas.uri_username == doggy assert uac.uri_username != doggy assert scen.name == "uas_uac"
def test_scenario(): uas, uac = agent.server(), agent.client() agents = [uas, uac] scen = agent.Scenario(agents) scen2 = agent.Scenario(agents) # verify contained agents assert list(scen.agents.values()) == agents == scen._agents assert scen.prepare() != agents # new copies # verify order agents = list(scen.agents.values()) assert uas is agents[0] assert uac is agents[1] # verify servers assert uas is list(scen.servers.values())[0] # verify clients assert uac is list(scen.clients.values())[0] # ensure defaults attr setting works doggy = 'doggy' scen.local_host = doggy uas, uac = scen.prepare() assert uac.local_host == uas.local_host == doggy # should be no shared state between instances assert scen2.local_host != doggy scen2.local_host = 10 assert scen.local_host == doggy # same error for any non-spec defined agent attr with pytest.raises(AttributeError): scen.agentdefaults.local_man = 'flasher' scen.prepare() # defaults on servers only scen.serverdefaults.uri_username = doggy uas, uac = scen.prepare() assert uas.uri_username == doggy assert uac.uri_username != doggy assert scen.name == 'uas_uac'
def test_agent_fails(): uas = server(call_count=1) # apply bogus ip which can't be bound uas.local_host, uas.local_port = '99.99.99.99', 5060 # client calls server at bogus addr uac = client(destaddr=(uas.local_host, uas.local_port)) uac.recv_timeout = 1 # avoids SIPp issue #176 uac.call_count = 1 # avoids SIPp issue #176 runner = run_blocking(uas, uac) # fails due to invalid ip uasproc = runner.get(timeout=0)[uas.render()] assert uasproc.streams.stderr assert uasproc.returncode == 255, uasproc.streams.stderr # killed by signal uacproc = runner.get(timeout=0)[uac.render()] # assert not uacproc.streams.stderr # sometimes this has a log msg? ret = uacproc.returncode # killed by SIGUSR1 or terminates before it starts (racy) assert ret == -10 or ret == 0
def default_agents(): uas = agent.server(local_host='127.0.0.1', local_port=5060, call_count=1) uac = agent.client(call_count=1, destaddr=(uas.local_host, uas.local_port)) return uas, uac
def test_server(): ua = agent.server() cmdstr = ua.render() assert "-sn 'uas'" in cmdstr assert not (ua.remote_host and ua.remote_port)
def test_server(): ua = agent.server() cmdstr = ua.render() assert "-sn 'uas'" in cmdstr assert not (ua.remote_host and ua.remote_port) @pytest.mark.parametrize('ua, retcode, kwargs, exc', [ # test unspecialized ua failure (agent.ua(), 255, {}, RuntimeError), # test client failure on bad remote destination (agent.client(destaddr=('99.99.99.99', 5060)), 1, {}, RuntimeError), # test if server times out it is signalled (agent.server(), 0, {'timeout': 1}, launch.TimeoutError)], ids=['ua', 'uac', 'uas'], ) def test_failures(ua, retcode, kwargs, exc): """Test failure cases for all types of agents """ # run it without raising runner = ua(raise_exc=False, **kwargs) cmds2procs = runner.get(timeout=0) assert not runner.is_alive() assert len(list(runner.iterprocs())) == 0 # tests transparency of the defaults config pipeline scen = plugin.mng.hook.pysipp_conf_scen_protocol( agents=[ua], confpy=None, scenkwargs={}) cmd = scen.prepare_agent(ua).render() assert cmd in cmds2procs
def test_server(): ua = agent.server() cmdstr = ua.render() assert "-sn 'uas'" in cmdstr assert not (ua.remote_host and ua.remote_port) @pytest.mark.parametrize( "ua, retcode, kwargs, exc", [ # test unspecialized ua failure (agent.ua(), 255, {}, RuntimeError), # test client failure on bad remote destination (agent.client(destaddr=("99.99.99.99", 5060)), 1, {}, RuntimeError), # test if server times out it is signalled (agent.server(), 0, { "timeout": 1 }, launch.TimeoutError), ], ids=["ua", "uac", "uas"], ) def test_failures(ua, retcode, kwargs, exc): """Test failure cases for all types of agents""" # run it without raising runner = ua(raise_exc=False, **kwargs) cmds2procs = runner.get(timeout=0) assert not runner.is_alive() assert len(list(runner.iterprocs())) == 0 # tests transparency of the defaults config pipeline scen = plugin.mng.hook.pysipp_conf_scen_protocol(agents=[ua], confpy=None,