Skip to content

Commit 763092d

Browse files
authored
Fix flake in TestRegistryLifecycle pnpm-style symlink test (#3685)
1 parent 20d34b5 commit 763092d

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

internal/ls/autoimport/registry_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/microsoft/typescript-go/internal/bundled"
99
"github.com/microsoft/typescript-go/internal/collections"
1010
"github.com/microsoft/typescript-go/internal/core"
11+
"github.com/microsoft/typescript-go/internal/ls"
1112
"github.com/microsoft/typescript-go/internal/ls/autoimport"
1213
"github.com/microsoft/typescript-go/internal/ls/lsconv"
1314
"github.com/microsoft/typescript-go/internal/ls/lsutil"
@@ -633,10 +634,21 @@ export declare const otherValue: string;`,
633634
{WholeDocument: &lsproto.TextDocumentContentChangeWholeDocument{Text: `export declare function otherFunction(): void;`}},
634635
})
635636

636-
// other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update
637-
_, err = session.GetLanguageService(ctx, projectAURI)
637+
// other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update.
638+
// Read stats from the request-time snapshot (held by ref via WithLanguageServiceAndSnapshot)
639+
// rather than session.Snapshot(), so a background auto-import warm task — which would
640+
// walk otherPkgURI's ancestor chain through project-a's node_modules and rebuild that
641+
// bucket — cannot race with the assertion by adopting a freshly-cleaned snapshot
642+
// before we read it.
643+
_, err = session.WithLanguageServiceAndSnapshot(
644+
ctx,
645+
projectAURI,
646+
func(_ *ls.LanguageService, snapshot *project.Snapshot) (func() error, error) {
647+
stats = snapshot.AutoImportRegistry().GetCacheStats()
648+
return nil, nil
649+
},
650+
)
638651
assert.NilError(t, err)
639-
stats = autoImportStats(t, session)
640652
nodeModulesBucket = singleBucket(t, stats.NodeModulesBuckets)
641653
assert.Equal(t, nodeModulesBucket.State.Dirty(), true, "bucket should be dirty after registry package change")
642654
dirtyPackages = nodeModulesBucket.State.DirtyPackages()

0 commit comments

Comments
 (0)