Debian Codegraph @

embedfs/concurrent_readat_test.go

raw symbols SCIP
1 package embedfsscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/
2
3 import (
4 "embedscip-go gomod github.com/golang/go/src go1.25.0 embed/"
5 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
6 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
7
8 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/"
9 )
10
11 //go:embed testdata/concurrent.bin
12 var concurrentFSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/concurrentFS. embedscip-go gomod github.com/golang/go/src go1.25.0 embed/.FSscip-go gomod github.com/golang/go/src go1.25.0 embed/FS#
13
14 // TestFileConcurrentReadAt asserts that concurrent ReadAt calls on a
15 // shared embedfs file handle are safe under -race and return correct
16 // per-byte results. embedfs wraps bytes.Reader, which is already
17 // concurrent-safe for ReadAt; this test pins the billy.File.ReadAt
18 // contract so future changes to the wrapper cannot regress it.
19 func TestFileConcurrentReadAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/TestFileConcurrentReadAt().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
20 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
21
22 want, err := concurrentFSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/concurrentFS..ReadFilescip-go gomod github.com/golang/go/src go1.25.0 embed/FS#ReadFile().("testdata/concurrent.bin")
23 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err)
24 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, 4096, len(want))
25
26 fs := Newscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/New().(&concurrentFSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/embedfs`/concurrentFS.)
27 f, err := fs.Openscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Basic#Open.("testdata/concurrent.bin")
28 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err)
29 t.Cleanupscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Cleanup().(func() { _ = f.Closescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/File#Close().() })
30
31 const workers = 8
32 const iters = 200
33 const bufLen = 64
34
35 var wg syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#
36 wg.Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(workers)
37 for w := range workers {
38 go func() {
39 defer wg.Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().()
40 buf := make([]byte, bufLen)
41 for i := range iters {
42 off := int64((w*131 + i*257) % (len(want) - bufLen))
43 n, err := f.ReadAtscip-go gomod github.com/golang/go/src go1.25.0 io/ReaderAt#ReadAt().(buf, off)
44 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err)
45 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, bufLen, n)
46 requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Equal().(t, want[off:off+int64(n)], buf[:n])
47 }
48 }()
49 }
50 wg.Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().()
51 }