MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / test_engine

Function test_engine

bbot/test/test_step_1/test_engine.py:5–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4@pytest.mark.asyncio
5async def test_engine():
6 from bbot.core.engine import EngineClient, EngineServer
7
8 counter = 0
9 yield_cancelled = False
10 yield_errored = False
11 return_started = False
12 return_finished = False
13 return_cancelled = False
14 return_errored = False
15
16 class TestEngineServer(EngineServer):
17 CMDS = {
18 0: "return_thing",
19 1: "yield_stuff",
20 }
21
22 async def return_thing(self, n):
23 nonlocal return_started
24 nonlocal return_finished
25 nonlocal return_cancelled
26 nonlocal return_errored
27 try:
28 return_started = True
29 await asyncio.sleep(n)
30 return_finished = True
31 return f"thing{n}"
32 except asyncio.CancelledError:
33 return_cancelled = True
34 raise
35 except Exception:
36 return_errored = True
37 raise
38
39 async def yield_stuff(self, n):
40 nonlocal counter
41 nonlocal yield_cancelled
42 nonlocal yield_errored
43 try:
44 for i in range(n):
45 yield f"thing{i}"
46 counter += 1
47 await asyncio.sleep(0.1)
48 except asyncio.CancelledError:
49 yield_cancelled = True
50 raise
51 except Exception:
52 yield_errored = True
53 raise
54
55 class TestEngineClient(EngineClient):
56 SERVER_CLASS = TestEngineServer
57
58 async def return_thing(self, n):
59 return await self.run_and_return("return_thing", n)
60
61 async def yield_stuff(self, n):
62 async for _ in self.run_and_yield("yield_stuff", n):

Callers

nothing calls this directly

Calls 5

return_thingMethod · 0.95
yield_stuffMethod · 0.95
TestEngineClientClass · 0.85
cancelMethod · 0.80
shutdownMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…