X Tutup
Skip to content

fix(workspaceapps): use fresh context in LastUsedAt assertions#22863

Open
johnstcn wants to merge 1 commit intomainfrom
fix/flaky-proxy-error-last-used-at
Open

fix(workspaceapps): use fresh context in LastUsedAt assertions#22863
johnstcn wants to merge 1 commit intomainfrom
fix/flaky-proxy-error-last-used-at

Conversation

@johnstcn
Copy link
Member

@johnstcn johnstcn commented Mar 9, 2026

Summary

The assertWorkspaceLastUsedAtUpdated and assertWorkspaceLastUsedAtNotUpdated test helpers previously accepted a context.Context, which callers shared with preceding HTTP requests. In ProxyError tests the request targets a fake unreachable app (http://127.1.0.1:396), and the reverse-proxy connection timeout can consume most of the context budget — especially on Windows — leaving too little time for the testutil.Eventually polling loop and causing flakes.

Changes

Replace the context.Context parameter with a time.Duration so each assertion creates its own fresh context internally. This:

  • Makes the timeout budget explicit at every call site
  • Structurally prevents shared-context starvation
  • Fixes the class of flake, not just the two known-failing subtests

All 34 active call sites updated to pass testutil.WaitLong.

Fixes coder/internal#1385

The assertWorkspaceLastUsedAtUpdated and
assertWorkspaceLastUsedAtNotUpdated helpers previously accepted a
context.Context, which callers shared with preceding HTTP requests.
In ProxyError tests the request targets a fake unreachable app,
and the reverse-proxy timeout can consume most of the context
budget — especially on Windows — leaving too little time for the
Eventually polling loop and causing flakes.

Replace the context parameter with a time.Duration so each
assertion creates its own fresh context. This makes the timeout
budget explicit at every call site and structurally prevents
shared-context starvation.

Fixes coder/internal#1385
@johnstcn johnstcn self-assigned this Mar 9, 2026
@johnstcn johnstcn marked this pull request as ready for review March 9, 2026 20:44
@johnstcn johnstcn requested review from Emyrk and Copilot March 9, 2026 20:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates workspace app test helpers to avoid flakiness caused by reusing a partially-consumed context.Context (notably after reverse-proxy timeouts), by giving each LastUsedAt assertion a fresh timeout budget.

Changes:

  • Change assertWorkspaceLastUsedAtUpdated / assertWorkspaceLastUsedAtNotUpdated to accept a time.Duration and create a fresh context internally.
  • Update all call sites in the workspaceapps apptest suite to pass testutil.WaitLong.
  • Add explanatory comments documenting why a duration is preferred over a shared context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 124 to 125
// Even though path-based apps are disabled, the request should indicate
// that the workspace was used.
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The comment says the forbidden request "should indicate that the workspace was used", but the test calls assertWorkspaceLastUsedAtNotUpdated (i.e., expects LastUsedAt to not change). Please reconcile this mismatch by either updating the comment or switching to the *Updated assertion, so the test intent is unambiguous.

Suggested change
// Even though path-based apps are disabled, the request should indicate
// that the workspace was used.
// Even though path-based apps are disabled, this forbidden request should
// not indicate that the workspace was used.

Copilot uses AI. Check for mistakes.
@@ -377,7 +377,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
require.Equal(t, http.StatusBadGateway, resp.StatusCode)
// An valid authenticated attempt to access a workspace app
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Grammar: "An valid authenticated attempt" should be "A valid authenticated attempt".

Suggested change
// An valid authenticated attempt to access a workspace app
// A valid authenticated attempt to access a workspace app

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: TestWorkspaceProxyWorkspaceApps/WorkspaceAppsProxyPath/ProxyError

2 participants

X Tutup