tests: --batch-groups auto follows the engine's INFO batch_groups
This commit is contained in:
1 parent
886bc47742
commit
21d4165b16
1 file changed
+21
-3
+21
-3
@@ -25,7 +25,8 @@ FAKE_BATCH = r'''import queue, sys, threading, time
|
||||
args = sys.argv[1:]
|
||||
slots = int(args[args.index("--batch") + 1]) if "--batch" in args else 0
|
||||
fit = int(args[args.index("--fit") + 1]) if "--fit" in args else slots
|
||||
fail = "--fail-window" in args # #997: the first window over two slots fails
|
||||
fail = "--fail-window" in args
|
||||
groups = int(args[args.index("--says-groups") + 1]) if "--says-groups" in args else 0 # INFO batch_groups=G (--batch-groups auto) # #997: the first window over two slots fails
|
||||
STEP = 0.02
|
||||
CH = 32
|
||||
lines, stop = queue.Queue(), threading.Event()
|
||||
@@ -39,7 +40,7 @@ def reader():
|
||||
lines.put(None)
|
||||
threading.Thread(target=reader, daemon=True).start()
|
||||
print("INFO engine=0.1.39" + (f" batch_slots={fit}" if fit >= 2 else "") +
|
||||
(" slot_cache=1" if "--slotcache" in args else ""), flush=True)
|
||||
(" slot_cache=1" if "--slotcache" in args else "") + (f" batch_groups={groups}" if groups > 1 else ""), flush=True)
|
||||
print("READY 4096 stop", flush=True)
|
||||
LONG = list(b"LONGREPLY")
|
||||
def continued(ids): # (the whole reply, how much of it the prompt already ends with: a request continued)
|
||||
@@ -245,7 +246,7 @@ class PickSlot(unittest.TestCase):
|
||||
class ParallelService(unittest.TestCase):
|
||||
"""The real StrataEngine and Service over HTTP, the fake engine behind them."""
|
||||
|
||||
def start(self, slots, fit=None, slot_cache=False, fail=False, reuse=False):
|
||||
def start(self, slots, fit=None, slot_cache=False, fail=False, reuse=False, says_groups=0, more=()):
|
||||
import serve.server as server
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
script = Path(self.tmp.name) / "fake_strata.py"
|
||||
@@ -256,6 +257,8 @@ class ParallelService(unittest.TestCase):
|
||||
extra += ["--slotcache"] if slot_cache else []
|
||||
extra += ["--fail-window"] if fail else []
|
||||
extra += ["--reuse"] if reuse else []
|
||||
extra += ["--says-groups", str(says_groups)] if says_groups else []
|
||||
extra += list(more)
|
||||
with mock.patch.object(server.subprocess, "Popen",
|
||||
lambda cmd, **kw: real([sys.executable, str(script), *cmd[1:]], **kw)):
|
||||
self.engine = StrataEngine("strata", extra)
|
||||
@@ -296,6 +299,21 @@ class ParallelService(unittest.TestCase):
|
||||
self.assertEqual(self.engine.batch, 2)
|
||||
self.assertEqual(self.get("/v1/status")["concurrency"]["serving"], 2)
|
||||
|
||||
def test_batch_groups_auto_follows_the_engine(self):
|
||||
"""--batch-groups auto: the engine picks the groups and says so (INFO batch_groups=G); the server spreads the
|
||||
requests over those groups, and a plain number is read as before."""
|
||||
self.start(8, says_groups=4, more=["--batch-groups", "auto"])
|
||||
e = self.engine
|
||||
self.assertEqual((e.batch, e.slot_groups), (8, 4))
|
||||
self.assertEqual(e.slot_group, [0, 0, 1, 1, 2, 2, 3, 3])
|
||||
self.assertEqual(e.slot_order[:4], [0, 2, 4, 6])
|
||||
self.tearDown(); self.httpd = self.engine = self.tmp = None
|
||||
self.start(8, more=["--batch-groups", "auto"]) # an engine that reports none: one group
|
||||
self.assertEqual(self.engine.slot_groups, 1)
|
||||
self.tearDown(); self.httpd = self.engine = self.tmp = None
|
||||
self.start(8, more=["--batch-groups", "2"])
|
||||
self.assertEqual(self.engine.slot_groups, 2)
|
||||
|
||||
def test_stop_strings_in_a_batch_slot(self):
|
||||
"""#454: a stop string cuts the answer in --batch mode too, and the slot is freed for the next request."""
|
||||
self.start(2)
|
||||
|
||||
Reference in new issue
Block a user