chore: replace real time.Sleep with clockwork in unit tests#2627
Merged
chmouel merged 1 commit intotektoncd:mainfrom Apr 1, 2026
Merged
chore: replace real time.Sleep with clockwork in unit tests#2627chmouel merged 1 commit intotektoncd:mainfrom
chmouel merged 1 commit intotektoncd:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the clockwork library to the Gitea and GitHub providers to facilitate deterministic testing of retry and backoff logic. By replacing direct time package calls with a clock interface, tests can now use a fake clock to advance time instantly. Additionally, the PR reduces sleep durations in LLM provider tests to improve execution speed. The review feedback identifies a thread-safety issue in the lazy initialization of the clock field within both the Gitea and GitHub provider implementations, recommending a change to avoid potential data races when the clock is not explicitly set.
da2cf2f to
6fcd382
Compare
Inject clockwork.FakeClock into Gitea and GitHub provider retry/backoff loops so tests don't wait on real sleeps (~10s saved). Reduce LLM timeout test mock sleeps from 2s to 200ms. Fixes tektoncd#2594 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
6fcd382 to
49d8cbf
Compare
theakshaypant
approved these changes
Apr 1, 2026
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.
Summary
Fixes #2594
clockwork.FakeClockinto Gitea and GitHub provider structs so retry/backoff loops use a fake clock in tests instead of realtime.Sleep/time.AfterChanges
createStatusCommit)clockfield +getClock()lazy helper to ProvidergetPullRequestsWithCommit)clockfield to ProviderTestAnalyzeTimeoutTestAnalyzeTimeoutTest plan
go test ./pkg/provider/gitea/— all passgo test ./pkg/provider/github/— all passgo test ./pkg/llm/providers/gemini/— all passgo test ./pkg/llm/providers/openai/— all passgolangci-lint run— 0 issues🤖 Generated with Claude Code