test : HTTP window and environment lifecycle, and fix two request-handling bugs (PyTest - 2) - #1669
Open
Manik-Khajuria-5 wants to merge 16 commits into
Open
test : HTTP window and environment lifecycle, and fix two request-handling bugs (PyTest - 2)#1669Manik-Khajuria-5 wants to merge 16 commits into
Manik-Khajuria-5 wants to merge 16 commits into
Conversation
Adds conftest.py, a testutils package, and unit tests for window().
AsyncHTTPTestCase is a unittest.TestCase, and pytest will not inject fixtures into those. Run the Application on a background event loop instead and talk to it with requests, which is already a runtime dependency, so HTTP tests can be plain functions.
Lands the window lifecycle file as plain pytest functions on the visdom_server fixture, dropping the per-file setUp block and the temp directory it never cleaned up.
Collapses the repeated plot-trace and opts assertions into parametrized tables, so each case reports separately instead of hiding behind the first failure.
The reload case now builds its second Application from the app_factory fixture, which shares env_path with visdom_server, instead of hand-rolling one against a leaked temp directory.
The update-into-a-missing-env case asserted 'status is 200 or 500', which could not fail. It now pins the actual behaviour: 200 with 'win does not exist'.
register_window took the index from len(env), so closing any window but the last produced a duplicate index and the pane order went undefined after a reload. Use max(i) + 1, which is what the undo path already does.
Three validation checks used a bare assert, so an invalid request came back as a 500 and, under python -O, was skipped entirely: forking an unknown env then raised KeyError and a named trace update read past the data it was given. Raise HTTPError(400) like the other checks do.
Places the two test files dev added into the new layout, and points the new storage-wiring test at env_payload: it called the local _env helper this branch had already replaced, which merged cleanly and then failed.
Brings in dev along with the layout placement and the env_payload fix made on the PR-1 branch. D1 and D2 both survive the auto-merge of server_utils.py and web_handlers.py.
Replaces the background event loop and requests session with the AsyncHTTPTestCase base class from PR-1, which already runs the app in-process on an ephemeral port. The four integration files become TestCase subclasses; pytest still collects and marks them.
first/second read as two windows; they are the id returned by each call, which is the same id both times. Also assert only one pane exists.
The guidance still said VisdomHTTPTestCase was scheduled for replacement by a background-loop fixture. Record the opposite, and the consequences for anyone writing an HTTP test: no fixtures, no parametrize, share via a base class.
Contributor
There was a problem hiding this comment.
Sorry @Manik-Khajuria-5, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Contributor
Reviewer's GuideAdds a structured HTTP integration test harness and unit tests for window/env utilities, replaces ad-hoc fakes with reusable test helpers, tightens test configuration/docs, and fixes two HTTP request-handling bugs (window index allocation and bare-assert validation) in server code. Sequence diagram for HTTP env fork validation behaviorsequenceDiagram
actor Client
participant Application
participant web_handlers
participant handler
Client->>Application: POST /events (fork_env)
Application->>web_handlers: wrap_func(handler, args)
web_handlers->>web_handlers: prev_eid = escape_eid(args.get("prev_eid"))
web_handlers->>web_handlers: eid = escape_eid(args.get("eid"))
alt prev_eid not in handler.state
web_handlers-->>Client: HTTPError(400, reason=env to be forked doesn't exist)
else prev_eid in handler.state
web_handlers->>handler: handler.state[eid] = copy.deepcopy(handler.state[prev_eid])
web_handlers->>handler: handler.storage.save_env(eid, handler.state[eid])
handler-->>Client: 200 OK
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Manik-Khajuria-5
requested review from
Jayantparashar10,
Saksham-Sirohi,
marcoag,
mariobehling,
norbusan,
rajnisht7,
tonypzy and
vedansh-5
July 31, 2026 17:17
Manik-Khajuria-5
force-pushed
the
TestingP2
branch
from
August 1, 2026 08:28
0b8da74 to
336c990
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds 70 HTTP integration tests across four files in
py/tests/integration/, covering the window and environment lifecycle end to end, and fixes two bugs they exposed.test_window_lifecycle.py— create, exists, read, replace, close, orderingtest_window_types.py— every pane type throughPOST /eventstest_environment_lifecycle.py— implicit creation, fork, save, delete, reloadtest_edge_cases.py— eid escaping, error routes, malformed requests, awkward contentEach subclasses
VisdomHTTPTestCasefrom PR-1 and carriespytestmark = pytest.mark.integration. Three helpers (update,close_window,save) were added to the base class.Fixes : #1695
Integration note
This PR should be merged after #1668 , as it depends on the lower-layer changes introduced there.
Motivation and Context
Two defects had no test and are fixed here, each with a regression test:
Window indices could collide.
register_windowtook the index fromlen(env), so closing any window but the last handed the next one an index alr pane order became undefined after a reload. Nowmax(i) + 1, which is what the undo path atsocket_handlers.py:120already did.Three validation checks used a bare
assert. An invalid reques500 instead of a 400, and under
python -Othe checks vanished entirely forking an unknown env then raisedKeyError, and a named trace update read p given. They now raiseHTTPError(400)like the other checks in the file.One existing assertion,
assertIn(resp.code, (200, 500)), could not fail; it is replaced with the actual contract.How Has This Been Tested?
pytest -m "not server"371 passed, on a clean checkout, Pblack --check ./py(23.1.0) clean.python -Otoo, which is the point of the second fixpython example/demo.pyagainst a live server: 70 panes, contigu no server errors and no visible difference from a clean branch.Types of changes
Checklist:
py/visdom/VERSIONaccording to Semantic VersioningSummary by Sourcery
Add comprehensive HTTP integration and unit tests for window and environment lifecycle, strengthen request validation, and ensure window indexing and storage wiring behave correctly.
New Features:
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests:
Chores: