Skip to content

Commit 80a75d5

Browse files
committed
Fix race with default libs
1 parent 67f9911 commit 80a75d5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

internal/execute/testfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
type testFsTrackingLibs struct {
99
fs vfs.FS
10-
defaultLibs *collections.Set[string]
10+
defaultLibs *collections.SyncSet[string]
1111
}
1212

1313
var _ vfs.FS = (*testFsTrackingLibs)(nil)

internal/execute/testsys_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ type diffEntry struct {
7878

7979
type snapshot struct {
8080
snap map[string]*diffEntry
81-
defaultLibs *collections.Set[string]
81+
defaultLibs *collections.SyncSet[string]
8282
}
8383

8484
type testSys struct {
@@ -116,7 +116,7 @@ func (s *testSys) ensureLibPathExists(path string) {
116116
path = tscLibPath + "/" + path
117117
if _, ok := s.TestFS().ReadFile(path); !ok {
118118
if s.fs.defaultLibs == nil {
119-
s.fs.defaultLibs = collections.NewSetWithSizeHint[string](tsoptions.LibFilesSet.Len() + len(tsoptions.TargetToLibMap()) + 1)
119+
s.fs.defaultLibs = &collections.SyncSet[string]{}
120120
}
121121
s.fs.defaultLibs.Add(path)
122122
err := s.TestFS().WriteFile(path, tscDefaultLibContent, false)
@@ -225,20 +225,23 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
225225
}
226226
}
227227
}
228-
var defaultLibs *collections.Set[string]
228+
var defaultLibs collections.SyncSet[string]
229229
if s.fs.defaultLibs != nil {
230-
defaultLibs = s.fs.defaultLibs.Clone()
230+
s.fs.defaultLibs.Range(func(libPath string) bool {
231+
defaultLibs.Add(libPath)
232+
return true
233+
})
231234
}
232235
s.serializedDiff = &snapshot{
233236
snap: snap,
234-
defaultLibs: defaultLibs,
237+
defaultLibs: &defaultLibs,
235238
}
236239
fmt.Fprintln(baseline)
237240
}
238241

239242
func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry, path string) {
240243
var oldDirContent *diffEntry
241-
var defaultLibs *collections.Set[string]
244+
var defaultLibs *collections.SyncSet[string]
242245
if s.serializedDiff != nil {
243246
oldDirContent = s.serializedDiff.snap[path]
244247
defaultLibs = s.serializedDiff.defaultLibs

0 commit comments

Comments
 (0)