Skip to content

test(cuda.core): restore pyglet context after failed window setup - #2813

Merged
rwgk merged 3 commits into
NVIDIA:mainfrom
rluo8:test/chained-pyglet-gl-setup-failures
Sep 11, 2026
Merged

test(cuda.core): restore pyglet context after failed window setup#2813
rwgk merged 3 commits into
NVIDIA:mainfrom
rluo8:test/chained-pyglet-gl-setup-failures

Conversation

@rluo8

@rluo8 rluo8 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Description

This is to fix bug 6737103.
Test test_graphics.py failed with exception pyglet.gl.lib.GLException: (0x1282): Invalid operation. The specified operation is not allowed in the current state.
But when running the test case one by one, it could be skipped. If running the whole file like pytest -v test_graphics.py on a MCDM Windows system, it would fail.

The cause is that when pyglet window construction fails after creating a new GL context, it can leave a partially constructed window and stale current_context. The per-test cleanup in cuda.core collects the window, causing subsequent graphics tests to fail with GLException instead of skipping for the original unavailable GL capability.

Record the existing pyglet windows and current context before window construction. If construction fails, close newly created windows and restore the previous context before re-raising the original exception.

Signed-off-by: Rui Luo <ruluo@nvidia.com>
@rluo8 rluo8 self-assigned this Sep 11, 2026
@rluo8
rluo8 requested a review from juenglin September 11, 2026 09:35
@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Sep 11, 2026
@rluo8
rluo8 requested a review from Andy-Jost September 11, 2026 10:54
@rluo8 rluo8 changed the title test: restore pyglet context after failed window setup test(cuda.core): restore pyglet context after failed window setup Sep 11, 2026
@github-actions

This comment has been minimized.

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rluo8 , LGTM, based on a codex review (findings below).

I'll go ahead and merge this as-is. I'll work on the P2 finding in a follow-on PR, with the goal to get both fixes into ctk-next asap.

(I think it's reasonable to ignore the P3 finding.)

Findings gpt-5.6-sol ultra

  • P2 — Mirror the cleanup in bindings. cuda_bindings/tests/test_graphics_apis.py:37 retains the identical vulnerable Window(...) construction. Its parametrized test at cuda_bindings/tests/test_graphics_apis.py:105 can leave stale Pyglet state after the first skipped case. Apply the same fix there or centralize the lifecycle helper.
  • P3 — Add deterministic regression coverage. Nothing directly tests the snapshot/close/restore logic at cuda_core/tests/test_graphics.py:71. Current Windows CI skips earlier while importing pyglet.gl because opengl32 is unavailable, so it never exercises this branch. A mocked test should verify new windows close, the prior context is restored, and the original exception propagates.

@rwgk rwgk added this to the cuda.core 1.3.0 milestone Sep 11, 2026
@rwgk rwgk added the bug Something isn't working label Sep 11, 2026
@rwgk
rwgk merged commit 6332121 into NVIDIA:main Sep 11, 2026
222 of 225 checks passed
@github-actions

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants