Skip to content

flake: TestTokens #1379

@flake-investigator

Description

@flake-investigator

CI Failure

Failure Output

--- FAIL: TestTokens
    tokens_test.go:191:
        Error Trace: C:/actions-runner/coder/coder/cli/tokens_test.go:191
        Error:       Should be true

Relevant log context shows the admin tokens rm call succeeded, but the follow-up assertion failed:

clitest.go:86: invoking command: coder ... tokens rm oAqUzRa1fj
... PUT /api/v2/users/me/keys/oAqUzRa1fj/expire ... status_code=204
... tokens_test.go:191: Error: Should be true

Suspected Root Cause

Flaky test on Windows due to timing/clock precision around expiration. The test asserts:

require.True(t, token.ExpiresAt.Before(time.Now()))

ExpireAPIKey sets ExpiresAt using dbtime.Now() (UTC + microsecond rounding). On Windows (coarser clock resolution), ExpiresAt can be equal to or slightly after time.Now() at assertion time, causing intermittent failure.

Assignment Analysis

git blame -L 185,195 cli/tokens_test.go

  • 4a3304fc38d0 (feat(cli)!: expire tokens by default) — added the failing assertion and the expire-path test
  • Author: Cian Johnston (johnstcn)

Notes

  • No panic/OOM/race indicators in logs.
  • Only failure in run; other OS jobs passed.

Suggested Fix

Relax the time assertion, e.g.:

  • require.False(t, token.ExpiresAt.After(time.Now())), or
  • compare against time.Now().Add(1 * time.Second) / use assert.WithinDuration.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions