From 3857376a2f2fe11d2cd805a7576a786e62f6743a Mon Sep 17 00:00:00 2001 From: youheyu Date: Tue, 13 Oct 2026 11:06:51 +0800 Subject: [PATCH] tests: the slow-read list's immediate re-ask is asked within its own retry window (#1889) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestTaggedReposSlowRead 在负载下(load ~28)误报一次:晚到读取的轮询上限 10s 与 taggedRetry=1s 重叠,轮询加首次调用超过 retry 窗口后,被截断的列表 被(正确地)再问,测试把它当成 bug。按 LESSONS 注入 1.2s 延迟复现 ("asked again at once: 3"),随后修复并保持延迟下通过。 修法:把「不重问」断言放在它自己的 retry 窗口内——断言前将 taggedAt 移到 now,断言后(含 Fatal 分支)还原。窗口与轮询耗时不重叠,测试两边留余量 (code standards: a timing test leaves room on both sides)。「past taggedRetry」步骤仍用还原后的真实窗口,sleep 与断言语义不变。 验证:注入延迟下旧代码 FAIL(asked again at once: 3)、新代码 PASS; -count=3 通过;TestTaggedRepos 不受影响。 Changed on review: moving taggedAt to now made the step ask about a whole list (held ten minutes), so a cut-short list no longer held for taggedRetry passed the test. The step now marks the list cut short now, as TaggedRepos does, and the hold itself is checked right after the cut-short ask: held till between ask-start+taggedRetry and ask-end+taggedRetry, bounds from the clock with no slack to outgrow. Run: old test + 1.2s injected before the step: FAIL "asked again at once: 3"; new test + the same delay: ok. Hold broken by hand (-taggedTTL) and doubled (2*taggedRetry): both FAIL at the new bound. -count=5 TestTaggedRepos*: ok. Full internal/plugin (-tags nogui): ok, 649s under load. --- internal/plugin/github_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/plugin/github_test.go b/internal/plugin/github_test.go index 207fa607f..6fe9791a8 100644 --- a/internal/plugin/github_test.go +++ b/internal/plugin/github_test.go @@ -289,13 +289,24 @@ func TestTaggedReposSlowRead(t *testing.T) { } return nil } + cutAsked := time.Now() l := TaggedRepos(ctx) + cutDone := time.Now() if x := has(l, "someone/word-guard"); len(l) != 6 || x == nil || x.Kind != "middleware" { t.Fatalf("slow package.json: %d repos, word-guard %+v", len(l), x) } if n := asked.Load(); n != 2 { t.Fatalf("asked %d times", n) } + // the list cut short is held for taggedRetry from when it was asked, + // no more and no less: bounds from the clock around the ask, so no + // slack a loaded runner could outgrow (#1889) + taggedMu.Lock() + until := taggedAt.Add(taggedTTL) + taggedMu.Unlock() + if until.Before(cutAsked.Add(taggedRetry)) || until.After(cutDone.Add(taggedRetry)) { + t.Fatalf("a list cut short held till %v, asked between %v and %v", until, cutAsked, cutDone) + } // nor is the list cut short kept ten minutes by a magpie started again if fi, err := os.Stat(taggedCache()); err != nil || time.Since(fi.ModTime()) < taggedTTL-taggedRetry-time.Second { t.Fatalf("the copy on disk stands till %v", fi.ModTime().Add(taggedTTL)) @@ -321,8 +332,16 @@ func TestTaggedReposSlowRead(t *testing.T) { time.Sleep(10 * time.Millisecond) } - // within the ten minutes, but past taggedRetry: asked again, and - // word-guard's package.json not read again + // within the ten minutes, but not yet past taggedRetry: not asked + // again, and word-guard's package.json not read again. The poll for + // the late read can take longer than taggedRetry on a loaded runner + // (once it did, at load ~28, #1889), and a list cut short is then + // asked again rightly; that it is held for taggedRetry is checked + // above, against the clock around the ask. Here it is marked as cut + // short now, as TaggedRepos marks one, and must not be asked again. + taggedMu.Lock() + taggedAt = time.Now().Add(-taggedTTL + taggedRetry) + taggedMu.Unlock() TaggedRepos(ctx) if n := asked.Load(); n != 2 { t.Fatalf("asked again at once: %d", n)