test : Cover the socket handlers and fix the five crashes that surfaced (PyTest - 5) - #1673
Open
Manik-Khajuria-5 wants to merge 31 commits into
Open
test : Cover the socket handlers and fix the five crashes that surfaced (PyTest - 5)#1673Manik-Khajuria-5 wants to merge 31 commits into
Manik-Khajuria-5 wants to merge 31 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.
Both halves now run off VisdomHTTPTestCase instead of their own fixture block.
The three cap tables collapse onto parametrize; the file was untracked until now.
Guard the missing-point check behind a numeric test, and stop indexing data and traces past their length when an update supplies fewer entries than the plot.
It was the one history pane that grew without bound.
Removing a heatmap names no trace and posts no data, so the shortcut for opts-only updates returned before the delete branch and left the plot up.
Contributor
There was a problem hiding this comment.
Sorry @Manik-Khajuria-5, your pull request is larger than the review limit of 150000 diff characters
Contributor
Reviewer's GuideAdds comprehensive unit and integration tests around socket handlers, window/environment lifecycle, server utilities, and data model durability, and fixes several crashes and edge cases in plot updates, embeddings drill-down, layout broadcasting, environment forking, and atomic persistence, while refactoring test structure and tightening memory caps and defaults. Sequence diagram for updated plot update and heatmap delete handlingsequenceDiagram
actor Client
participant UpdateHandler as UpdateHandler
Client->>UpdateHandler: update_packet(p, args, max_text_lines, max_old_content, max_image_history, max_plot_history)
Note over Client,UpdateHandler: args may include name, data, delete, update="remove" (heatmap)
UpdateHandler->>UpdateHandler: update(p, args, max_text_lines, max_old_content, max_image_history, max_plot_history)
alt utype == plot_history
UpdateHandler->>UpdateHandler: append frame to p["content"]
UpdateHandler->>UpdateHandler: trim to max_plot_history
UpdateHandler->>UpdateHandler: set p["selected"]
else utype == plot_update
UpdateHandler->>UpdateHandler: update_window(p, args)
UpdateHandler->>UpdateHandler: read delete, name, data
alt delete is falsy and name is None and not data
UpdateHandler-->>Client: return p (opts/layout-only update)
else delete is truthy
UpdateHandler->>UpdateHandler: remove selected traces from p["content"]["data"]
UpdateHandler-->>Client: return p (heatmap trace removed)
end
end
UpdateHandler-->>Client: p with contentID set
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
August 1, 2026 13:04
8 tasks
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
socket_handlers.pyhad no test coverage. This adds 122 integration tests (test_socket_lifecycle.py,test_socket_commands.py, plus atestutils/sockets.pyhelper that drives the real handlers without a WebSocket) and fixes what writing them turned up:broadcast_layoutswas araise ValueErrorstub on the base class, so a source socket sendingsave_layoutscrashed.Pane close popped the pane twice, so sources always saw
pane_data: None.A non-integer
plot_historyframe raisedTypeError— the range check ran before any type check.pop_embeddings_paneraised on an exhausted history; now logs and drops.heatmap(update="remove")stopped removing the plot: it posts{"data": [], "delete": True}with noname, andnot []isTrue, so the opts-only shortcut returned before the delete branch.Fixes : #1695
Integration note
This PR should be merged after #1672 , as it depends on the lower-layer changes introduced there.
How Has This Been Tested?
pytest py/tests— 716 passed under Python 3.12.13 (594 pred branch, unchanged).Fix 5 end to end against a running server with the real client: t
1 → 0with the fix,1 → 1without.Each socket fix has a test that fails without it.
black --checkScreenshots (if appropriate):
n/a the two
plot_surface_remove*screenshots go back to matchinTypes of changes
Checklist:
py/visdom/VERSIONaccording to Semantic VersioningSummary by Sourcery
Add comprehensive socket and window lifecycle test coverage, harden plotting and embeddings updates, and improve persistence durability and configuration for tests and packaging.
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: