Skip to content

test: fix flaky image timestamp check on coarse clocks#13588

Merged
fuweid merged 1 commit into
containerd:mainfrom
austinvazquez:fix-flaky-images-create-update-delete-test
Jun 22, 2026
Merged

test: fix flaky image timestamp check on coarse clocks#13588
fuweid merged 1 commit into
containerd:mainfrom
austinvazquez:fix-flaky-images-create-update-delete-test

Conversation

@austinvazquez

@austinvazquez austinvazquez commented Jun 12, 2026

Copy link
Copy Markdown
Member

TestImagesCreateUpdateDelete asserts that an image's updatedat is strictly after its createdat. Both timestamps are stamped via time.Now().UTC(), which strips the monotonic reading, so the comparison falls back to the wall clock. On platforms with coarse timer resolution (e.g. Windows, which advances system time at the ~15.6ms tick), the Create and Update calls can land in the same tick and produce identical timestamps, making the strict After() check fail intermittently.

Wait for the wall clock to advance past the creation timestamp before updating so the assertion stays meaningful without depending on clock resolution. On fine-resolution clocks the loop runs zero iterations.

Testing

Before

~/Workspace/containerd (main)
$ go test -run ^TestImagesCreateUpdateDelete$ -count 2 ./core/metadata/
--- FAIL: TestImagesCreateUpdateDelete (0.03s)
    --- FAIL: TestImagesCreateUpdateDelete/ReplaceLabelsAnnotationsFieldPath (0.00s)
        images_test.go:579: timestamp for updatedat not after createdat: 2026-06-12 19:46:25.9847699 +0000 UTC <= 2026-06-12 19:46:25.9847699 +0000 UTC
FAIL
FAIL    github.com/containerd/containerd/v2/core/metadata       0.430s
FAIL

After

~/Workspace/containerd (fix-flaky-images-create-update-delete-test)
$ go test -run ^TestImagesCreateUpdateDelete$ -count 1000 ./core/metadata/
ok      github.com/containerd/containerd/v2/core/metadata       26.076s

Additional context

  • === Failed
    === FAIL: core/metadata TestImagesCreateUpdateDelete/ReplaceLabelsAnnotationsFieldPath (0.01s)
    images_test.go:579: timestamp for updatedat not after createdat: 2026-06-12 17:11:33.7569733 +0000 UTC <= 2026-06-12 17:11:33.7569733 +0000 UTC

Seen in https://github.com/containerd/containerd/actions/runs/27430461506/job/81079589148

TestImagesCreateUpdateDelete asserts that an image's updatedat is
strictly after its createdat. Both timestamps are stamped via
time.Now().UTC(), which strips the monotonic reading, so the comparison
falls back to the wall clock. On platforms with coarse timer resolution
(e.g. Windows, which advances system time at the ~15.6ms tick), the
Create and Update calls can land in the same tick and produce identical
timestamps, making the strict After() check fail intermittently.

Wait for the wall clock to advance past the creation timestamp before
updating so the assertion stays meaningful without depending on clock
resolution. On fine-resolution clocks the loop runs zero iterations.

Signed-off-by: Austin Vazquez <[email protected]>

Copilot AI 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.

Pull request overview

This PR fixes a flaky timestamp assertion in TestImagesCreateUpdateDelete by ensuring the wall clock advances between the image Create and Update operations, avoiding intermittent failures on coarse-resolution clocks (notably Windows).

Changes:

  • Adds a wait loop before calling store.Update to ensure the next time.Now() wall-clock value is strictly after the creation timestamp.
  • Documents the root cause (loss of monotonic clock reading via time.Now().UTC() and coarse wall-clock ticks).

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

Comment thread core/metadata/images_test.go

@kunalworldwide kunalworldwide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean fix for a real flake — on Windows (or any platform with coarse timer resolution), two back-to-back time.Now().UTC() calls can return the same value, so UpdatedAt equals CreatedAt and the strict ordering assertion fails.

The spin-wait approach is fine for a test — time.Sleep(time.Millisecond) is cheap and the loop exits as soon as the clock ticks forward. The comment explains the root cause well.

One minor thought: if you wanted to avoid the spin entirely, you could relax the assertion from After to !Before (i.e., allow equal timestamps). But that would weaken the test's intent, so I think the wait is the better choice here — it preserves the strict ordering guarantee.

LGTM.

@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Jun 16, 2026
@dmcgowan
dmcgowan added this pull request to the merge queue Jun 16, 2026
@dmcgowan dmcgowan added the cherry-pick/2.3.x Change to be cherry picked to release/2.3 label Jun 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 16, 2026
@fuweid
fuweid added this pull request to the merge queue Jun 22, 2026
Merged via the queue into containerd:main with commit 3fcad51 Jun 22, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 22, 2026
@fuweid

fuweid commented Jun 22, 2026

Copy link
Copy Markdown
Member

/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@fuweid: new pull request created: #13643

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@fuweid fuweid added cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch size/S

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants