Skip to content

Commit 1b3ba86

Browse files
authored
Merge pull request #2083 from ktock/fusedev1
test: enable passthrough mode in all layer tests
2 parents 1e3ef72 + 82999f5 commit 1b3ba86

File tree

1 file changed

+56
-33
lines changed

1 file changed

+56
-33
lines changed

fs/layer/testutil.go

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,53 @@ var srcCompressions = map[string]tutil.CompressionFactory{
7171
"externaltoc-gzip-bestspeed": tutil.ExternalTOCGzipCompressionWithLevel(gzip.BestSpeed),
7272
}
7373

74+
type layerConfig struct {
75+
name string
76+
passThroughConfig passThroughConfig
77+
}
78+
7479
func TestSuiteLayer(t *testing.T, store metadata.Store) {
75-
testPrefetch(t, store)
76-
testNodeRead(t, store)
77-
testPassThroughRead(t, store)
78-
testNodes(t, store)
80+
for _, lc := range []layerConfig{
81+
{
82+
name: "default",
83+
passThroughConfig: passThroughConfig{
84+
enable: false,
85+
},
86+
},
87+
{
88+
name: "passthrough",
89+
passThroughConfig: passThroughConfig{
90+
enable: true,
91+
mergeBufferSize: 419430400,
92+
mergeWorkerCount: 10,
93+
},
94+
},
95+
{
96+
name: "passthorough without concorrency",
97+
passThroughConfig: passThroughConfig{
98+
enable: true,
99+
mergeBufferSize: 419430400,
100+
mergeWorkerCount: 1,
101+
},
102+
},
103+
{
104+
name: "passthorough with small buffer",
105+
passThroughConfig: passThroughConfig{
106+
enable: true,
107+
mergeBufferSize: 1,
108+
mergeWorkerCount: 10,
109+
},
110+
},
111+
} {
112+
testPrefetch(t, store, lc)
113+
testNodeRead(t, store, lc)
114+
testNodes(t, store, lc)
115+
}
79116
}
80117

81118
var testStateLayerDigest = digest.FromString("dummy")
82119

83-
func testPrefetch(t *testing.T, factory metadata.Store) {
120+
func testPrefetch(t *testing.T, factory metadata.Store, lc layerConfig) {
84121
data64KB := string(tutil.RandomBytes(t, 64000))
85122
defaultPrefetchSize := int64(10000)
86123
landmarkPosition := func(t *testing.T, l *layer) int64 {
@@ -181,7 +218,7 @@ func testPrefetch(t *testing.T, factory metadata.Store) {
181218
for _, tt := range tests {
182219
for srcCompressionName, srcCompression := range srcCompressions {
183220
cl := srcCompression()
184-
t.Run("testPrefetch-"+tt.name+"-"+srcCompressionName, func(t *testing.T) {
221+
t.Run("testPrefetch-"+tt.name+"-"+srcCompressionName+"-"+lc.name, func(t *testing.T) {
185222
chunkSize := sampleChunkSize
186223
if tt.chunkSize > 0 {
187224
chunkSize = tt.chunkSize
@@ -219,9 +256,7 @@ func testPrefetch(t *testing.T, factory metadata.Store) {
219256
ocispec.Descriptor{Digest: testStateLayerDigest},
220257
&blobRef{blob, func(bool) {}},
221258
vr,
222-
passThroughConfig{
223-
enable: false,
224-
},
259+
lc.passThroughConfig,
225260
)
226261
if err := l.Verify(dgst); err != nil {
227262
t.Errorf("failed to verify reader: %v", err)
@@ -383,15 +418,7 @@ const (
383418
lastChunkOffset1 = sampleChunkSize * (int64(len(sampleData1)) / sampleChunkSize)
384419
)
385420

386-
func testPassThroughRead(t *testing.T, factory metadata.Store) {
387-
nodeRead(t, factory, true)
388-
}
389-
390-
func testNodeRead(t *testing.T, factory metadata.Store) {
391-
nodeRead(t, factory, false)
392-
}
393-
394-
func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
421+
func testNodeRead(t *testing.T, factory metadata.Store, lc layerConfig) {
395422
sizeCond := map[string]int64{
396423
"single_chunk": sampleChunkSize - sampleMiddleOffset,
397424
"multi_chunks": sampleChunkSize + sampleMiddleOffset,
@@ -416,7 +443,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
416443
for fn, filesize := range fileSizeCond {
417444
for _, srcCompression := range srcCompressions {
418445
cl := srcCompression()
419-
t.Run(fmt.Sprintf("reading_%s_%s_%s_%s", sn, in, bo, fn), func(t *testing.T) {
446+
t.Run(fmt.Sprintf("reading_%s_%s_%s_%s_%s", sn, in, bo, fn, lc.name), func(t *testing.T) {
420447
if filesize > int64(len(sampleData1)) {
421448
t.Fatal("sample file size is larger than sample data")
422449
}
@@ -440,7 +467,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
440467
}
441468

442469
// data we get from the file node.
443-
f, closeFn := makeNodeReader(t, []byte(sampleData1)[:filesize], sampleChunkSize, factory, cl, pth)
470+
f, closeFn := makeNodeReader(t, []byte(sampleData1)[:filesize], sampleChunkSize, factory, cl, lc)
444471
defer closeFn()
445472
tmpbuf := make([]byte, size) // fuse library can request bigger than remain
446473
rr, errno := f.Read(context.Background(), tmpbuf, offset)
@@ -471,7 +498,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
471498
}
472499
}
473500

474-
func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metadata.Store, cl tutil.Compression, pth bool) (_ *file, closeFn func() error) {
501+
func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metadata.Store, cl tutil.Compression, lc layerConfig) (_ *file, closeFn func() error) {
475502
testName := "test"
476503
sr, tocDgst, err := tutil.BuildEStargz(
477504
[]tutil.TarEntry{tutil.File(testName, string(contents))},
@@ -484,7 +511,7 @@ func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metada
484511
if err != nil {
485512
t.Fatalf("failed to create reader: %v", err)
486513
}
487-
rootNode := getRootNode(t, r, OverlayOpaqueAll, tocDgst, cache.NewMemoryCache(), pth)
514+
rootNode := getRootNode(t, r, OverlayOpaqueAll, tocDgst, cache.NewMemoryCache(), lc)
488515
var eo fuse.EntryOut
489516
inode, errno := rootNode.Lookup(context.Background(), testName, &eo)
490517
if errno != 0 {
@@ -499,13 +526,13 @@ func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metada
499526
return f.(*file), r.Close
500527
}
501528

502-
func testNodes(t *testing.T, factory metadata.Store) {
529+
func testNodes(t *testing.T, factory metadata.Store, lc layerConfig) {
503530
for _, o := range []OverlayOpaqueType{OverlayOpaqueAll, OverlayOpaqueTrusted, OverlayOpaqueUser} {
504-
testNodesWithOpaque(t, factory, o)
531+
testNodesWithOpaque(t, factory, o, lc)
505532
}
506533
}
507534

508-
func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpaqueType) {
535+
func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpaqueType, lc layerConfig) {
509536
data64KB := string(tutil.RandomBytes(t, 64000))
510537
hasOpaque := func(entry string) check {
511538
return func(t *testing.T, root *node, cc cache.BlobCache, cr *calledReaderAt) {
@@ -714,7 +741,7 @@ func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpa
714741
for _, tt := range tests {
715742
for _, srcCompression := range srcCompressions {
716743
cl := srcCompression()
717-
t.Run(tt.name, func(t *testing.T) {
744+
t.Run(tt.name+"-"+lc.name, func(t *testing.T) {
718745
opts := []tutil.BuildEStargzOption{
719746
tutil.WithEStargzOptions(estargz.WithCompression(cl)),
720747
}
@@ -736,7 +763,7 @@ func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpa
736763
}
737764
defer r.Close()
738765
mcache := cache.NewMemoryCache()
739-
rootNode := getRootNode(t, r, opaque, tocDgst, mcache, false)
766+
rootNode := getRootNode(t, r, opaque, tocDgst, mcache, lc)
740767
for _, want := range tt.want {
741768
want(t, rootNode, mcache, testR)
742769
}
@@ -745,7 +772,7 @@ func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpa
745772
}
746773
}
747774

748-
func getRootNode(t *testing.T, r metadata.Reader, opaque OverlayOpaqueType, tocDgst digest.Digest, cc cache.BlobCache, pth bool) *node {
775+
func getRootNode(t *testing.T, r metadata.Reader, opaque OverlayOpaqueType, tocDgst digest.Digest, cc cache.BlobCache, lc layerConfig) *node {
749776
vr, err := reader.NewReader(r, cc, digest.FromString(""))
750777
if err != nil {
751778
t.Fatalf("failed to create reader: %v", err)
@@ -754,11 +781,7 @@ func getRootNode(t *testing.T, r metadata.Reader, opaque OverlayOpaqueType, tocD
754781
if err != nil {
755782
t.Fatalf("failed to verify reader: %v", err)
756783
}
757-
rootNode, err := newNode(testStateLayerDigest, rr, &testBlobState{10, 5}, 100, opaque, passThroughConfig{
758-
enable: pth,
759-
mergeBufferSize: 419430400,
760-
mergeWorkerCount: 10,
761-
})
784+
rootNode, err := newNode(testStateLayerDigest, rr, &testBlobState{10, 5}, 100, opaque, lc.passThroughConfig)
762785
if err != nil {
763786
t.Fatalf("failed to get root node: %v", err)
764787
}

0 commit comments

Comments
 (0)