test(provider): TestFetchNewLeavesListedPlugins waits for the refresh its sign-in started, and TestFetchNewRetriedSoon puts back what it set — signing in with a key (PluginAPIKey) shows the account, which lists the providers while the host's auth event has them stale, so Cached refreshes them in the background; that refresh could end after the test had set the list's time back, rewriting plugin-providers.json, which read as FetchNew asking the plugins again (failed 3 in 5 run after TestFetchNewRetriedSoon, and now and then after TestFetchNewAccount). plugin.Refreshed waits for those refreshes with the host left running, and the test waits before it sets the time. TestFetchNewRetriedSoon now resets newFetches, newSoonAt, wbTokens and the account caches, after waiting for a FetchNewSoon under way. The pair passes 10 in 10 (and with TestFetchNewAccount 10 in 10); ./internal/provider 3 in 3; go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass.

This commit is contained in:
yetone
2026-10-01 21:49:16 +08:00
parent 171d8dc646
commit ad1c8fd1ec
3 changed files with 19 additions and 0 deletions
+4
View File
@@ -250,6 +250,10 @@ func UseCached(ps []Provider) {
// refreshing is Cached's refreshes in the background.
var refreshing sync.WaitGroup
// Refreshed waits for Cached's refreshes in the background to end, the
// host left running: for tests that watch the providers' list on disk.
func Refreshed() { refreshing.Wait() }
// Settle waits for Cached's refreshes to end, then stops the host: for
// tests, whose folders the host runs in go when they end.
func Settle() {
+11
View File
@@ -30,6 +30,17 @@ func TestFetchNewRetriedSoon(t *testing.T) {
newFetches.m = map[string]time.Time{}
newFetches.Unlock()
newSoonAt.Store(0)
t.Cleanup(func() {
waitNewSoon()
newFetches.Lock()
newFetches.m = map[string]time.Time{}
newFetches.Unlock()
newSoonAt.Store(0)
wbTokens.Lock()
wbTokens.m = map[string]wbCreds{}
wbTokens.Unlock()
forgetAccountCaches()
})
var asked atomic.Int32
var down atomic.Bool
@@ -42,6 +42,10 @@ func TestFetchNewLeavesListedPlugins(t *testing.T) {
if p, err := Find("fakeco"); err != nil || !p.IsPlugin() || !p.Ready() {
t.Fatalf("Find(fakeco) = %+v, %v", p, err)
}
// signing in kicked off a refresh of the plugins' providers in the
// background (Cached, after the auth event); one still running
// rewrites the list below and reads as FetchNew asking again
plugin.Refreshed()
was := newFetchRetry
newFetchRetry = 0
t.Cleanup(func() { newFetchRetry = was })