def test_stream_modify(self): s = script.Script( tutils.test_data.path("data/addonscripts/stream_modify.py")) self.master.addons.add(s) d = self.pathod('200:b"foo"') assert d.content == b"bar" self.master.addons.remove(s)
def tscript(cmd, args=""): o = options.Options() cmd = example_dir.path(cmd) + " " + args m = RaiseMaster(o, None, state.State()) sc = script.Script(cmd) m.addons.add(o, sc) return m, sc
def tscript(cmd, args=""): o = options.Options() cmd = example_dir.path(cmd) + " " + args m = RaiseMaster(o, proxy.DummyServer()) sc = script.Script(cmd) m.addons.add(sc) return m, sc
def test_concurrent_err(self): m = mastertest.RecordingMaster(options.Options(), proxy.DummyServer()) sc = script.Script( tutils.test_data.path( "data/addonscripts/concurrent_decorator_err.py")) with m.handlecontext(): sc.start() assert "decorator not supported" in m.event_log[0][1]
def test_addon(self): s = state.State() o = options.Options() m = master.FlowMaster(o, None, s) sc = script.Script(tutils.test_data.path("data/addonscripts/addon.py")) m.addons.add(sc) assert sc.ns.event_log == [ 'scriptstart', 'addonstart', 'addonconfigure' ]
def test_exception(self): s = state.State() o = options.Options() m = mastertest.RecordingMaster(o, None, s) sc = script.Script(tutils.test_data.path("data/addonscripts/error.py")) m.addons.add(o, sc) f = tutils.tflow(resp=True) m.request(f) assert m.event_log[0][0] == "error"
def test_tcp_stream_modify(self): s = script.Script( tutils.test_data.path("data/addonscripts/tcp_stream_modify.py")) self.master.addons.add(self.master.options, s) self._tcpproxy_on() d = self.pathod('200:b"foo"') self._tcpproxy_off() assert d.content == b"bar" self.master.addons.remove(s)
def test_duplicate_flow(self): s = state.State() o = options.Options() fm = master.FlowMaster(o, None, s) fm.addons.add( script.Script( tutils.test_data.path("data/addonscripts/duplicate_flow.py"))) f = tutils.tflow() fm.request(f) assert fm.state.flow_count() == 2 assert not fm.state.view[0].request.is_replay assert fm.state.view[1].request.is_replay
def test_addon(self): o = options.Options() m = master.Master(o, proxy.DummyServer()) sc = script.Script( tutils.test_data.path( "data/addonscripts/addon.py" ) ) m.addons.add(sc) assert sc.ns.event_log == [ 'scriptstart', 'addonstart', 'addonconfigure' ]
def test_concurrent(self): m = master.Master(options.Options(), proxy.DummyServer()) sc = script.Script( tutils.test_data.path("data/addonscripts/concurrent_decorator.py")) m.addons.add(sc) f1, f2 = tutils.tflow(), tutils.tflow() m.request(f1) m.request(f2) start = time.time() while time.time() - start < 5: if f1.reply.state == f2.reply.state == "committed": return raise ValueError("Script never acked")
def test_concurrent(self): s = state.State() m = master.FlowMaster(options.Options(), None, s) sc = script.Script( tutils.test_data.path("data/addonscripts/concurrent_decorator.py")) m.addons.add(m.options, sc) f1, f2 = tutils.tflow(), tutils.tflow() self.invoke(m, "request", f1) self.invoke(m, "request", f2) start = time.time() while time.time() - start < 5: if f1.reply.acked and f2.reply.acked: return raise ValueError("Script never acked")
def test_exception(self): s = state.State() o = options.Options() m = mastertest.RecordingMaster(o, None, s) sc = script.Script(tutils.test_data.path("data/addonscripts/error.py")) m.addons.add(sc) f = tutils.tflow(resp=True) m.request(f) assert m.event_log[0][0] == "error" assert len(m.event_log[0][1].splitlines()) == 6 assert 'addonscripts/error.py", line 7, in request' in m.event_log[0][ 1] assert 'addonscripts/error.py", line 3, in mkerr' in m.event_log[0][1] assert m.event_log[0][1].endswith("ValueError: Error!\n")
def test_exception(self): o = options.Options() m = mastertest.RecordingMaster(o, proxy.DummyServer()) sc = script.Script( tutils.test_data.path("data/addonscripts/error.py") ) m.addons.add(sc) f = tutils.tflow(resp=True) m.request(f) assert m.event_log[0][0] == "error" assert len(m.event_log[0][1].splitlines()) == 6 assert re.search('addonscripts/error.py", line \d+, in request', m.event_log[0][1]) assert re.search('addonscripts/error.py", line \d+, in mkerr', m.event_log[0][1]) assert m.event_log[0][1].endswith("ValueError: Error!\n")
def test_simple(self): s = state.State() o = options.Options() m = master.FlowMaster(o, None, s) sc = script.Script( tutils.test_data.path("data/addonscripts/recorder.py")) m.addons.add(sc) assert sc.ns.call_log == [("solo", "start", (), {}), ("solo", "configure", (o, o.keys()), {})] sc.ns.call_log = [] f = tutils.tflow(resp=True) m.request(f) recf = sc.ns.call_log[0] assert recf[1] == "request"
def test_reload(self): o = options.Options() m = mastertest.RecordingMaster(o, proxy.DummyServer()) with tutils.tmpdir(): with open("foo.py", "w"): pass sc = script.Script("foo.py") m.addons.add(sc) for _ in range(100): with open("foo.py", "a") as f: f.write(".") m.addons.invoke_with_context(sc, "tick") time.sleep(0.1) if m.event_log: return raise AssertionError("Change event not detected.")