Skip to content

Commit 0275a89

Browse files
committed
fixes, tests, cleanup
1 parent 6980e73 commit 0275a89

12 files changed

Lines changed: 62 additions & 7 deletions

examples/cli/cli_wrapper_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
iterations = 500
1414

1515
for _ in range(iterations):
16-
with torch.inference_mode():
17-
output = model(batch)
16+
with torch.inference_mode():
17+
output = model(batch)
1818

1919
# print("output shape:", tuple(output.shape))

examples/feedback_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@
4848
print(
4949
f"run {i + 1}: confidence={confidence:.3f}{handle.last_inference_id[:8]}..."
5050
)
51+
52+
client.close()

examples/gguf_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
result = llm(prompt, max_tokens=128, temperature=0.7)
3434
text = result["choices"][0]["text"].strip()
3535
print(f"Q: {prompt}\nA: {text}\n")
36+
37+
client.close()

examples/gguf_gemma_manual_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@
114114
except Exception as exc:
115115
handle.track_error(error_code="UNKNOWN", error_message=str(exc)[:200])
116116
raise
117+
118+
client.close()

examples/keras_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@
4242
for _ in range(3):
4343
output = model.predict(batch, verbose=0)
4444
print("output shape:", output.shape)
45+
46+
client.close()

examples/onnx_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
2525
for _ in range(3):
2626
outputs = session.run(None, {"pixel_values": batch})
2727
print("output shape:", outputs[0].shape)
28+
29+
client.close()

examples/pytorch_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ def forward(self, x):
4040
for _ in range(3):
4141
output = model(batch)
4242
print("output shape:", output.shape)
43+
44+
client.close()

examples/timm_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
for _ in range(3):
3434
output = model(batch)
3535
print("output shape:", output.shape)
36+
37+
client.close()

tests/test_cli.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from wildedge.integrations.registry import IntegrationSpec
1010
from wildedge.runtime import bootstrap
1111
from wildedge.runtime import runner as runtime_runner
12+
from wildedge.settings import read_runtime_env
1213

1314

1415
def _fake_execle(captured: dict):
@@ -55,7 +56,7 @@ def test_cli_run_execs_command_with_env(monkeypatch):
5556
assert captured["env"][constants.ENV_STRICT_INTEGRATIONS] == "0"
5657
assert captured["env"][constants.ENV_PRINT_STARTUP_REPORT] == "0"
5758
assert captured["env"][constants.ENV_FLUSH_TIMEOUT] == str(
58-
constants.DEFAULT_SHUTDOWN_FLUSH_TIMEOUT_SEC
59+
constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
5960
)
6061

6162

@@ -148,7 +149,7 @@ def test_install_runtime_requires_dsn(monkeypatch):
148149
bootstrap.install_runtime()
149150

150151

151-
def test_install_runtime_default_flush_timeout_is_shutdown_budget(monkeypatch):
152+
def test_install_runtime_default_flush_timeout_is_runtime_budget(monkeypatch):
152153
class FakeWildEdge:
153154
SUPPORTED_INTEGRATIONS = {"onnx"}
154155

@@ -171,7 +172,7 @@ def close(self): # type: ignore[no-untyped-def]
171172

172173
context = bootstrap.install_runtime()
173174
try:
174-
assert context.flush_timeout == constants.DEFAULT_SHUTDOWN_FLUSH_TIMEOUT_SEC
175+
assert context.flush_timeout == constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
175176
finally:
176177
context.shutdown()
177178

@@ -471,3 +472,42 @@ def test_parse_run_args_only_double_dash_raises():
471472
"""['--'] with nothing after raises ValueError."""
472473
with pytest.raises(ValueError, match="missing command"):
473474
cli.parse_run_args(["--"])
475+
476+
477+
def test_cli_run_default_flush_timeout_is_nonzero(monkeypatch):
478+
"""CLI must pass a non-zero flush timeout so reservoir events are sent at shutdown."""
479+
captured: dict = {}
480+
monkeypatch.setattr(cli.os, "execle", _fake_execle(captured))
481+
monkeypatch.setattr(cli.shutil, "which", lambda cmd: f"/usr/bin/{cmd}")
482+
483+
cli.main(["run", "--", "gunicorn", "myapp.wsgi:app"])
484+
485+
flush_timeout = float(captured["env"][constants.ENV_FLUSH_TIMEOUT])
486+
assert flush_timeout > 0, (
487+
"flush timeout must be > 0 so reservoir inference events are flushed at shutdown"
488+
)
489+
assert flush_timeout == constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
490+
491+
492+
def test_cli_run_flush_timeout_override(monkeypatch):
493+
"""--flush-timeout arg is forwarded to child process."""
494+
captured: dict = {}
495+
monkeypatch.setattr(cli.os, "execle", _fake_execle(captured))
496+
monkeypatch.setattr(cli.shutil, "which", lambda cmd: f"/usr/bin/{cmd}")
497+
498+
cli.main(["run", "--flush-timeout", "10.0", "--", "gunicorn", "myapp.wsgi:app"])
499+
500+
assert captured["env"][constants.ENV_FLUSH_TIMEOUT] == "10.0"
501+
502+
503+
def test_read_runtime_env_default_flush_timeout_is_nonzero():
504+
"""read_runtime_env must default to a non-zero flush timeout when env var is absent."""
505+
env = {constants.ENV_DSN: "https://secret@ingest.wildedge.dev/key"}
506+
result = read_runtime_env(all_integrations=[], all_hubs=[], environ=env)
507+
assert result.flush_timeout > 0
508+
assert result.flush_timeout == constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC
509+
510+
511+
def test_runtime_flush_timeout_constant_is_nonzero():
512+
"""Guard: DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC must stay > 0."""
513+
assert constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC > 0

wildedge/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def build_parser() -> argparse.ArgumentParser:
4949
run.add_argument(
5050
"--flush-timeout",
5151
type=float,
52-
default=constants.DEFAULT_SHUTDOWN_FLUSH_TIMEOUT_SEC,
52+
default=constants.DEFAULT_RUNTIME_FLUSH_TIMEOUT_SEC,
5353
help="Flush timeout (seconds) for shutdown.",
5454
)
5555
run.add_argument(

0 commit comments

Comments
 (0)