Skip to content

Commit

Permalink
work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Nov 29, 2024
1 parent ff0c88e commit b975c83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/hypofuzz/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def pytest_collection_finish(self, session: pytest.Session) -> None:
self.fuzz_targets.append(fuzz)
except Exception as err:
print("crashed in", item.nodeid, err) # noqa
raise


def _get_hypothesis_tests_with_pytest(args: Iterable[str]) -> List["FuzzProcess"]:
Expand Down
45 changes: 33 additions & 12 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import pytest
import requests
import subprocess
import os
import signal

from hypofuzz import entrypoint

TEST_CODE = """
from hypothesis import given, settings, strategies as st
Expand Down Expand Up @@ -31,15 +33,34 @@ def test_end_to_end(numprocesses, tmp_path):
"""An end-to-end test to start the fuzzer and access the dashboard."""
test_fname = tmp_path / "test_demo2.py"
test_fname.write_text(TEST_CODE, encoding="utf-8")
dash_proc = entrypoint._fuzz_impl(
numprocesses=numprocesses,
dashboard=True,
port=7777,
unsafe=False,
pytest_args=["-p", "no:dash", str(test_fname)],
process = subprocess.Popen(
[
"hypothesis",
"fuzz",
"--numprocesses",
str(numprocesses),
"--port",
"7777",
"--",
"-p",
"no:dash",
str(test_fname),
],
stdout=subprocess.PIPE,
start_new_session=True
)
assert dash_proc
resp = requests.get("http://localhost:7777", allow_redirects=True, timeout=10)
resp.raise_for_status()
dash_proc.kill()
dash_proc.join()
# wait for dashboard to start up
for _ in range(100):
output = process.stdout.readline()
if b"Now serving dashboard at" in output:
break
else:
raise Exception("dashboard took too long to start up")

try:
resp = requests.get("http://localhost:7777", allow_redirects=True, timeout=10)
resp.raise_for_status()
finally:
process.stdout.close()
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
process.wait()

0 comments on commit b975c83

Please # to comment.