<#7461 fix: deflake ExampleNewAutoRefreshCache> Pu...
# flyte-github
a
#7461 fix: deflake ExampleNewAutoRefreshCache Pull request opened by pingsutw Why are the changes needed?
ExampleNewAutoRefreshCache
in
flytestdlib/autorefreshcache
is flaky in CI (failing run):
Copy code
--- FAIL: ExampleNewAutoRefreshCache (0.01s)
got:
Current status for item1 is Not-started
want:
Current status for item1 is Completed
The example slept a fixed
resyncPeriod * 10
(10ms) and then asserted that
item1
had reached the terminal
Completed
status. That transition is performed by the cache's async background refresh worker, so 10ms is not guaranteed to be enough on a slow/contended CI runner — the item is still
Not-started
when the assertion runs. This is a classic fixed-duration-wait-for-async-work race. What changes were proposed in this pull request? Replace the fixed
time.Sleep
with condition-based polling: poll
cache.Get
every
resyncPeriod
until
item1
reaches its terminal state (
Completed
), guarded by a 10s safety deadline. This removes the timing dependency while keeping the example's
// Output:
deterministic. How was this patch tested? •
go build
/
go vet
of the package pass;
go test -race ./flytestdlib/autorefreshcache/
passes. • Ran the example 200x via separate
go test
invocations under heavy CPU load (both before and after the change). Note: I was not able to reproduce the original CI flake locally even under load — the failure appears specific to the CI runner's scheduling. The change is therefore justified primarily by the root cause (a fixed 10ms wait for asynchronous work), not by a local repro. • Caveat worth knowing for reviewers: Go's
testing
package does not honor
-count
for
Example
functions (verified separately), so stressing an example requires repeated
go test
invocations rather than
-count=N
. Labels • fixed: deflakes a CI example test. Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. flyteorg/flyte