From dde155098357ae543797a277d464ce09cb114ae5 Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 11 Nov 2026 14:57:48 +0530 Subject: [PATCH] Name-lookup test counts only its own game's lookups The scan also reads the real Steam install on the machine running the test, and looks up any game there the offline dictionary lacks. Every lookup was counted, so the test failed on a PC with such a game installed: two lookups on the first scan, and a third on the second, since a name that is not found is not cached. The count now covers only the test's own game, and is atomic, as lookups run concurrently. --- internal/presets/presets_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/presets/presets_test.go b/internal/presets/presets_test.go index f2cfbabe..06750327 100644 --- a/internal/presets/presets_test.go +++ b/internal/presets/presets_test.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" "sync" + "sync/atomic" "testing" ) @@ -189,13 +190,18 @@ func TestResolveNames_UsesResolverAndCachesResult(t *testing.T) { } cacheFile := filepath.Join(t.TempDir(), "steam-app-cache.json") - calls := 0 + // Only this game's lookups are counted. The scan also reads the real + // Steam install on the machine running the test (the registry is not + // isolated), and a game there that the offline dictionary lacks is + // looked up too, from other goroutines; counting it failed the test on + // any PC with such a game installed. + var calls atomic.Int32 sc := &Scanner{ CacheFile: cacheFile, SteamUserdataPaths: []string{userdata}, ResolveAppName: func(appID string) string { - calls++ if appID == "99999999" { + calls.Add(1) return "Obscure Test Game" } return "" @@ -212,8 +218,8 @@ func TestResolveNames_UsesResolverAndCachesResult(t *testing.T) { if hit == nil || hit.Name != "Obscure Test Game" { t.Fatalf("resolver name not applied: %+v", hit) } - if calls != 1 { - t.Errorf("resolver called %d times, want 1", calls) + if n := calls.Load(); n != 1 { + t.Errorf("resolver called %d times, want 1", n) } // Second scan must hit the disk cache, not the resolver. @@ -223,8 +229,8 @@ func TestResolveNames_UsesResolverAndCachesResult(t *testing.T) { t.Errorf("cached name not used on second scan: %+v", found[i]) } } - if calls != 1 { - t.Errorf("resolver should not be called again after caching, total calls = %d", calls) + if n := calls.Load(); n != 1 { + t.Errorf("resolver should not be called again after caching, total calls = %d", n) } }