Debian Codegraph @

memfs/concurrent_readat_test.go

raw symbols SCIP
1 package memfsscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/memfs`/
2
3 import (
4 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
5 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
6
7 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/"
8 )
9
10 // TestFileConcurrentReadAt asserts that concurrent ReadAt calls on a
11 // shared memfs file handle are safe under -race and return correct
12 // per-byte results. memfs is the in-memory billy backing that go-git
13 // and other consumers rely on for tests; the billy.File.ReadAt
14 // contract documents concurrent-safety as required, and this test
15 // pins memfs's compliance.
16 func TestFileConcurrentReadAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/memfs`/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#) {
17 t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().()
18
19 const size = 64 * 1024
20 want := make([]byte, size)
21 for i := range want {
22 want[i] = byte(i % 251)
23 }
24
25 fs := Newscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/memfs`/New().()
26 f, err := fs.Createscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Basic#Create.("data")
27 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)
28 _, err = f.Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(want)
29 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)
30 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, f.Closescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/File#Close().())
31
32 rf, err := fs.Openscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Basic#Open.("data")
33 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)
34 t.Cleanupscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Cleanup().(func() { _ = rf.Closescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/File#Close().() })
35
36 const workers = 8
37 const iters = 200
38 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#
39 wg.Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(workers)
40 for w := range workers {
41 go func() {
42 defer wg.Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().()
43 buf := make([]byte, 1024)
44 for i := range iters {
45 off := int64((w*131 + i*257) % (len(want) - len(buf)))
46 n, err := rf.ReadAtscip-go gomod github.com/golang/go/src go1.25.0 io/ReaderAt#ReadAt().(buf, off)
47 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)
48 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, len(buf), n)
49 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])
50 }
51 }()
52 }
53 wg.Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().()
54 }