Skip to content

Commit

Permalink
storage: add smoking test for chunk dedup
Browse files Browse the repository at this point in the history
Add smoking test case for chunk dedup.

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Dec 7, 2023
1 parent 0e5793b commit ac55d88
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
75 changes: 75 additions & 0 deletions smoke/tests/chunk_dedup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2023 Nydus Developers. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

package tests

import (
"path/filepath"
"testing"

"github.com/containerd/nydus-snapshotter/pkg/converter"
"github.com/dragonflyoss/image-service/smoke/tests/texture"
"github.com/dragonflyoss/image-service/smoke/tests/tool"
"github.com/dragonflyoss/image-service/smoke/tests/tool/test"
"github.com/opencontainers/go-digest"
"github.com/stretchr/testify/require"
)

const (
paramIteration = "iteration"
)

type ChunkDedupTestSuite struct {
t *testing.T
}

func (z *ChunkDedupTestSuite) TestChunkDedup() test.Generator {

scenarios := tool.DescartesIterator{}
scenarios.Dimension(paramIteration, []interface{}{1, 2})

return func() (name string, testCase test.Case) {
if !scenarios.HasNext() {
return
}
scenario := scenarios.Next()

ctx := tool.DefaultContext(z.t)
ctx.Runtime.ChunkDedupDbFile = ctx.Env.WorkDir + "/cas.db"

return scenario.Str(), func(t *testing.T) {
z.testMakeLayers(*ctx, t)
}
}
}

func (z *ChunkDedupTestSuite) testMakeLayers(ctx tool.Context, t *testing.T) {

// Prepare work directory
ctx.PrepareWorkDir(t)
defer ctx.Destroy(t)

lowerLayer := texture.MakeLowerLayer(t, filepath.Join(ctx.Env.WorkDir, "source"))
lowerOCIBlobDigest, lowerRafsBlobDigest := lowerLayer.PackRef(t, ctx, ctx.Env.BlobDir, ctx.Build.OCIRefGzip)
mergeOption := converter.MergeOption{
BuilderPath: ctx.Binary.Builder,
ChunkDictPath: "",
OCIRef: true,
}
actualDigests, lowerBootstrap := tool.MergeLayers(t, ctx, mergeOption, []converter.Layer{
{
Digest: lowerRafsBlobDigest,
OriginalDigest: &lowerOCIBlobDigest,
},
})
require.Equal(t, []digest.Digest{lowerOCIBlobDigest}, actualDigests)

// Verify lower layer mounted by nydusd
ctx.Env.BootstrapPath = lowerBootstrap
tool.Verify(t, ctx, lowerLayer.FileTree)
}

func TestChunkDedup(t *testing.T) {
test.Run(t, &ChunkDedupTestSuite{t: t})
}
1 change: 1 addition & 0 deletions smoke/tests/tool/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type RuntimeContext struct {
RafsMode string
EnablePrefetch bool
AmplifyIO uint64
ChunkDedupDb string
}

type EnvContext struct {
Expand Down
4 changes: 4 additions & 0 deletions smoke/tests/tool/nydusd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type NydusdConfig struct {
AccessPattern bool
PrefetchFiles []string
AmplifyIO uint64
ChunkDedupDb string
}

type Nydusd struct {
Expand Down Expand Up @@ -205,6 +206,9 @@ func (nydusd *Nydusd) Mount() error {
if len(nydusd.BootstrapPath) > 0 {
args = append(args, "--bootstrap", nydusd.BootstrapPath)
}
if len(nydusd.ChunkDedupDb) > 0 {
args = append(args, "--dedup", nydusd.ChunkDedupDb)
}

cmd := exec.Command(nydusd.NydusdPath, args...)
cmd.Stdout = os.Stdout
Expand Down
1 change: 1 addition & 0 deletions smoke/tests/tool/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func Verify(t *testing.T, ctx Context, expectedFiles map[string]*File) {
RafsMode: ctx.Runtime.RafsMode,
DigestValidate: false,
AmplifyIO: ctx.Runtime.AmplifyIO,
ChunkDedupDb: ctx.Runtime.ChunkDedupDb,
}

nydusd, err := NewNydusd(config)
Expand Down

0 comments on commit ac55d88

Please sign in to comment.