@@ -71,16 +71,53 @@ var srcCompressions = map[string]tutil.CompressionFactory{
71
71
"externaltoc-gzip-bestspeed" : tutil .ExternalTOCGzipCompressionWithLevel (gzip .BestSpeed ),
72
72
}
73
73
74
+ type layerConfig struct {
75
+ name string
76
+ passThroughConfig passThroughConfig
77
+ }
78
+
74
79
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
+ }
79
116
}
80
117
81
118
var testStateLayerDigest = digest .FromString ("dummy" )
82
119
83
- func testPrefetch (t * testing.T , factory metadata.Store ) {
120
+ func testPrefetch (t * testing.T , factory metadata.Store , lc layerConfig ) {
84
121
data64KB := string (tutil .RandomBytes (t , 64000 ))
85
122
defaultPrefetchSize := int64 (10000 )
86
123
landmarkPosition := func (t * testing.T , l * layer ) int64 {
@@ -181,7 +218,7 @@ func testPrefetch(t *testing.T, factory metadata.Store) {
181
218
for _ , tt := range tests {
182
219
for srcCompressionName , srcCompression := range srcCompressions {
183
220
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 ) {
185
222
chunkSize := sampleChunkSize
186
223
if tt .chunkSize > 0 {
187
224
chunkSize = tt .chunkSize
@@ -219,9 +256,7 @@ func testPrefetch(t *testing.T, factory metadata.Store) {
219
256
ocispec.Descriptor {Digest : testStateLayerDigest },
220
257
& blobRef {blob , func (bool ) {}},
221
258
vr ,
222
- passThroughConfig {
223
- enable : false ,
224
- },
259
+ lc .passThroughConfig ,
225
260
)
226
261
if err := l .Verify (dgst ); err != nil {
227
262
t .Errorf ("failed to verify reader: %v" , err )
@@ -383,15 +418,7 @@ const (
383
418
lastChunkOffset1 = sampleChunkSize * (int64 (len (sampleData1 )) / sampleChunkSize )
384
419
)
385
420
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 ) {
395
422
sizeCond := map [string ]int64 {
396
423
"single_chunk" : sampleChunkSize - sampleMiddleOffset ,
397
424
"multi_chunks" : sampleChunkSize + sampleMiddleOffset ,
@@ -416,7 +443,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
416
443
for fn , filesize := range fileSizeCond {
417
444
for _ , srcCompression := range srcCompressions {
418
445
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 ) {
420
447
if filesize > int64 (len (sampleData1 )) {
421
448
t .Fatal ("sample file size is larger than sample data" )
422
449
}
@@ -440,7 +467,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
440
467
}
441
468
442
469
// 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 )
444
471
defer closeFn ()
445
472
tmpbuf := make ([]byte , size ) // fuse library can request bigger than remain
446
473
rr , errno := f .Read (context .Background (), tmpbuf , offset )
@@ -471,7 +498,7 @@ func nodeRead(t *testing.T, factory metadata.Store, pth bool) {
471
498
}
472
499
}
473
500
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 ) {
475
502
testName := "test"
476
503
sr , tocDgst , err := tutil .BuildEStargz (
477
504
[]tutil.TarEntry {tutil .File (testName , string (contents ))},
@@ -484,7 +511,7 @@ func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metada
484
511
if err != nil {
485
512
t .Fatalf ("failed to create reader: %v" , err )
486
513
}
487
- rootNode := getRootNode (t , r , OverlayOpaqueAll , tocDgst , cache .NewMemoryCache (), pth )
514
+ rootNode := getRootNode (t , r , OverlayOpaqueAll , tocDgst , cache .NewMemoryCache (), lc )
488
515
var eo fuse.EntryOut
489
516
inode , errno := rootNode .Lookup (context .Background (), testName , & eo )
490
517
if errno != 0 {
@@ -499,13 +526,13 @@ func makeNodeReader(t *testing.T, contents []byte, chunkSize int, factory metada
499
526
return f .(* file ), r .Close
500
527
}
501
528
502
- func testNodes (t * testing.T , factory metadata.Store ) {
529
+ func testNodes (t * testing.T , factory metadata.Store , lc layerConfig ) {
503
530
for _ , o := range []OverlayOpaqueType {OverlayOpaqueAll , OverlayOpaqueTrusted , OverlayOpaqueUser } {
504
- testNodesWithOpaque (t , factory , o )
531
+ testNodesWithOpaque (t , factory , o , lc )
505
532
}
506
533
}
507
534
508
- func testNodesWithOpaque (t * testing.T , factory metadata.Store , opaque OverlayOpaqueType ) {
535
+ func testNodesWithOpaque (t * testing.T , factory metadata.Store , opaque OverlayOpaqueType , lc layerConfig ) {
509
536
data64KB := string (tutil .RandomBytes (t , 64000 ))
510
537
hasOpaque := func (entry string ) check {
511
538
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
714
741
for _ , tt := range tests {
715
742
for _ , srcCompression := range srcCompressions {
716
743
cl := srcCompression ()
717
- t .Run (tt .name , func (t * testing.T ) {
744
+ t .Run (tt .name + "-" + lc . name , func (t * testing.T ) {
718
745
opts := []tutil.BuildEStargzOption {
719
746
tutil .WithEStargzOptions (estargz .WithCompression (cl )),
720
747
}
@@ -736,7 +763,7 @@ func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpa
736
763
}
737
764
defer r .Close ()
738
765
mcache := cache .NewMemoryCache ()
739
- rootNode := getRootNode (t , r , opaque , tocDgst , mcache , false )
766
+ rootNode := getRootNode (t , r , opaque , tocDgst , mcache , lc )
740
767
for _ , want := range tt .want {
741
768
want (t , rootNode , mcache , testR )
742
769
}
@@ -745,7 +772,7 @@ func testNodesWithOpaque(t *testing.T, factory metadata.Store, opaque OverlayOpa
745
772
}
746
773
}
747
774
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 {
749
776
vr , err := reader .NewReader (r , cc , digest .FromString ("" ))
750
777
if err != nil {
751
778
t .Fatalf ("failed to create reader: %v" , err )
@@ -754,11 +781,7 @@ func getRootNode(t *testing.T, r metadata.Reader, opaque OverlayOpaqueType, tocD
754
781
if err != nil {
755
782
t .Fatalf ("failed to verify reader: %v" , err )
756
783
}
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 )
762
785
if err != nil {
763
786
t .Fatalf ("failed to get root node: %v" , err )
764
787
}
0 commit comments