Skip to content

Commit

Permalink
fix: add tests for nydusify copy
Browse files Browse the repository at this point in the history
Signed-off-by: BruceAko <[email protected]>
  • Loading branch information
BruceAko committed Sep 10, 2024
1 parent 627f0e7 commit 269831f
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 43 deletions.
22 changes: 11 additions & 11 deletions smoke/tests/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// Environment Requirement: Containerd, nerdctl >= 0.22, nydus-snapshotter, nydusd, nydus-image and nydusify.
// Prepare: setup nydus for containerd, reference: https://github.com/dragonflyoss/nydus/blob/master/docs/containerd-env-setup.md.
// TestBenchmark will dump json file(benchmark.json) which includes container e2e time, image size, read-amount and read-cout.
// TestBenchmark will dump json file(benchmark.json) which includes container e2e time, image size, read-amount and read-count.
// Example:
// {
// e2e_time: 2747131
Expand Down Expand Up @@ -70,18 +70,18 @@ func (b *BenchmarkTestSuite) TestBenchmark(t *testing.T) {
}
targetImageSize, conversionElapsed := b.prepareImage(b.t, ctx, image)

// run contaienr
// run container
b.testContainerName = uuid.NewString()
containerMetic := tool.RunContainer(b.t, b.testImage, b.snapshotter, b.testContainerName)
containerMetric := tool.RunContainer(b.t, b.testImage, b.snapshotter, b.testContainerName)
b.metric = tool.ContainerMetrics{
E2ETime: containerMetic.E2ETime,
E2ETime: containerMetric.E2ETime,
ConversionElapsed: time.Duration(conversionElapsed),
ReadCount: containerMetic.ReadCount,
ReadAmountTotal: containerMetic.ReadAmountTotal,
ReadCount: containerMetric.ReadCount,
ReadAmountTotal: containerMetric.ReadAmountTotal,
ImageSize: targetImageSize,
}

// save metirc
// save metric
b.dumpMetric()
t.Logf(fmt.Sprintf("Metric: E2ETime %d ConversionElapsed %s ReadCount %d ReadAmount %d ImageSize %d", b.metric.E2ETime, b.metric.ConversionElapsed, b.metric.ReadCount, b.metric.ReadAmountTotal, b.metric.ImageSize))
}
Expand Down Expand Up @@ -120,18 +120,18 @@ func (b *BenchmarkTestSuite) prepareImage(t *testing.T, ctx *tool.Context, image
t.Fatalf("can't read convert metric file")
return 0, 0
}
var convertMetirc map[string]int64
err = json.Unmarshal(metricData, &convertMetirc)
var convertMetric map[string]int64
err = json.Unmarshal(metricData, &convertMetric)
if err != nil {
t.Fatalf("can't parsing convert metric file")
return 0, 0
}
if b.snapshotter == "nydus" {
b.testImage = target
return convertMetirc["TargetImageSize"], convertMetirc["ConversionElapsed"]
return convertMetric["TargetImageSize"], convertMetric["ConversionElapsed"]
}
b.testImage = source
return convertMetirc["SourceImageSize"], 0
return convertMetric["SourceImageSize"], 0
}

func (b *BenchmarkTestSuite) dumpMetric() {
Expand Down
4 changes: 4 additions & 0 deletions smoke/tests/blobcache_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2023 Nydus Developers. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

package tests

import (
Expand Down
10 changes: 5 additions & 5 deletions smoke/tests/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (c *CommitTestSuite) TestCommitContainer() test.Generator {
}
}

func (c *CommitTestSuite) TestCommitAndCheck(ctx tool.Context, image, commmitedImage string) {
// run nydus contaienr
func (c *CommitTestSuite) TestCommitAndCheck(ctx tool.Context, image, commitedImage string) {
// run nydus container
containerName := uuid.NewString()
runContainerCmd := fmt.Sprintf("sudo nerdctl --snapshotter nydus run -d -t --insecure-registry --name=%s %s sh", containerName, image)
containerID := strings.Trim(tool.RunWithOutput(runContainerCmd), "\n")
Expand All @@ -60,13 +60,13 @@ func (c *CommitTestSuite) TestCommitAndCheck(ctx tool.Context, image, commmitedI

// commit container
committedContainerName := fmt.Sprintf("%s-committed", containerName)
commitCmd := fmt.Sprintf("sudo %s commit --container %s --target %s", ctx.Binary.Nydusify, containerID, commmitedImage)
commitCmd := fmt.Sprintf("sudo %s commit --container %s --target %s", ctx.Binary.Nydusify, containerID, commitedImage)
tool.RunWithoutOutput(c.t, commitCmd)

// run committed container
runCommittedContainerCmd := fmt.Sprintf("sudo nerdctl --snapshotter nydus run -d -t --insecure-registry --name=%s %s sh", committedContainerName, commmitedImage)
runCommittedContainerCmd := fmt.Sprintf("sudo nerdctl --snapshotter nydus run -d -t --insecure-registry --name=%s %s sh", committedContainerName, commitedImage)
tool.RunWithOutput(runCommittedContainerCmd)
defer tool.ClearContainer(c.t, commmitedImage, "nydus", committedContainerName)
defer tool.ClearContainer(c.t, commitedImage, "nydus", committedContainerName)

// check committed file content
checkFileContent(c.t, committedContainerName, "/root/commit", "This is Nydus commit")
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/hot_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *HotUpgradeTestSuite) TestHotUpgrade(t *testing.T) {
err = newNydusd.StartByAPI()
require.NoError(t, err)

// Verify filesytem on new nydusd
// Verify filesystem on new nydusd
newNydusd.Verify(t, layer.FileTree)
}

Expand Down
39 changes: 35 additions & 4 deletions smoke/tests/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package tests

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/dragonflyoss/nydus/smoke/tests/tool"
"github.com/dragonflyoss/nydus/smoke/tests/tool/test"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -45,7 +47,7 @@ func (i *ImageTestSuite) TestConvertImages() test.Generator {
}

// Zran and Batch can not work together.
// Zran and Encrpt can not work together.
// Zran and Encrypt can not work together.
return (param.GetBool(paramZran) && param.GetString(paramBatch) != "0") ||
(param.GetBool(paramZran) && param.GetBool(paramEncrypt))
})
Expand Down Expand Up @@ -121,10 +123,12 @@ func (i *ImageTestSuite) TestConvertAndCopyImage(t *testing.T, ctx tool.Context,
)
tool.RunWithoutOutput(t, checkCmd)

if !testCopy {
return
if testCopy {
testNydusifyCopy(t, ctx, source, target, logLevel, nydusifyPath)
}
}

func testNydusifyCopy(t *testing.T, ctx tool.Context, source, target, logLevel, nydusifyPath string) {
// Copy image
targetCopied := fmt.Sprintf("%s_copied", target)
copyCmd := fmt.Sprintf(
Expand All @@ -135,11 +139,38 @@ func (i *ImageTestSuite) TestConvertAndCopyImage(t *testing.T, ctx tool.Context,
tool.RunWithoutOutput(t, copyCmd)

// Check copied image
checkCmd = fmt.Sprintf(
checkCmd := fmt.Sprintf(
"%s %s check --source %s --target %s --nydus-image %s --nydusd %s --work-dir %s",
nydusifyPath, logLevel, source, targetCopied, ctx.Binary.Builder, ctx.Binary.Nydusd, filepath.Join(ctx.Env.WorkDir, "check"),
)
tool.RunWithoutOutput(t, checkCmd)

// Save image
targetSaved := fmt.Sprintf("file://%s", filepath.Join(ctx.Env.WorkDir, "saved.tar"))
saveCmd := fmt.Sprintf(
"%s %s copy --source %s --target %s --nydus-image %s --work-dir %s",
ctx.Binary.Nydusify, logLevel, target, targetSaved, ctx.Binary.Builder, filepath.Join(ctx.Env.WorkDir, "save"),
)
tool.RunWithoutOutput(t, saveCmd)

// Check saved image
_, err := os.Stat(filepath.Join(ctx.Env.WorkDir, "saved.tar"))
require.NoError(t, err)

// Load image
targetLoaded := fmt.Sprintf("%s_loaded", target)
loadCmd := fmt.Sprintf(
"%s %s copy --source %s --target %s --nydus-image %s --work-dir %s",
ctx.Binary.Nydusify, logLevel, targetSaved, targetLoaded, ctx.Binary.Builder, filepath.Join(ctx.Env.WorkDir, "load"),
)
tool.RunWithoutOutput(t, loadCmd)

// Check loaded image
checkCmd = fmt.Sprintf(
"%s %s check --source %s --target %s --nydus-image %s --nydusd %s --work-dir %s",
nydusifyPath, logLevel, source, targetLoaded, ctx.Binary.Builder, ctx.Binary.Nydusd, filepath.Join(ctx.Env.WorkDir, "check"),
)
tool.RunWithoutOutput(t, checkCmd)
}

func (i *ImageTestSuite) TestGenerateChunkdicts() test.Generator {
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *PerformanceTestSuite) TestPerformance(_ *testing.T) {
// prepare test image
p.prepareTestImage(p.t, ctx, image)

// run Contaienr
// run Container
p.testContainerName = uuid.NewString()
tool.RunContainerWithBaseline(p.t, p.testImage, p.testContainerName, mode)
}
Expand Down
12 changes: 6 additions & 6 deletions smoke/tests/takeover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (f *TakeoverTestSuit) clear() {
tool.RunWithoutOutput(f.t, fmt.Sprintf("sudo nerdctl --snapshotter %s image rm %s", snapshotter, f.testImage))
}

func (f *TakeoverTestSuit) rmContainer(conatinerName string) {
tool.RunWithoutOutput(f.t, fmt.Sprintf("sudo nerdctl --snapshotter %s rm -f %s", snapshotter, conatinerName))
func (f *TakeoverTestSuit) rmContainer(containerName string) {
tool.RunWithoutOutput(f.t, fmt.Sprintf("sudo nerdctl --snapshotter %s rm -f %s", snapshotter, containerName))
}

func (f *TakeoverTestSuit) TestFailover(t *testing.T) {
Expand All @@ -82,10 +82,10 @@ func (f *TakeoverTestSuit) TestFailover(t *testing.T) {
// check the container by requesting its wait url
runArgs := tool.GetRunArgs(t, imageName)
resp, err := http.Get(runArgs.WaitURL)
require.NoError(t, err, "access to the wait url of the recoverd container")
require.NoError(t, err, "access to the wait url of the recovered container")
defer resp.Body.Close()
if resp.StatusCode/100 != 2 {
t.Fatalf("Failed to access the wait url of the recoverd container")
t.Fatalf("Failed to access the wait url of the recovered container")
}
}

Expand Down Expand Up @@ -120,10 +120,10 @@ func (f *TakeoverTestSuit) TestHotUpgrade(t *testing.T) {
// check the container by requesting its wait url
runArgs := tool.GetRunArgs(t, imageName)
resp, err := http.Get(runArgs.WaitURL)
require.NoError(t, err, "access to the wait url of the recoverd container")
require.NoError(t, err, "access to the wait url of the recovered container")
defer resp.Body.Close()
if resp.StatusCode/100 != 2 {
t.Fatalf("Failed to access the wait url of the recoverd container")
t.Fatalf("Failed to access the wait url of the recovered container")
}
}

Expand Down
10 changes: 5 additions & 5 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func RunContainerWithBaseline(t *testing.T, image string, containerName string,

// RunContainer and return container metric
func RunContainer(t *testing.T, image string, snapshotter string, containerName string) *ContainerMetrics {
var containerMetic ContainerMetrics
var containerMetric ContainerMetrics
startTime := time.Now()

// runContainer
Expand All @@ -182,17 +182,17 @@ func RunContainer(t *testing.T, image string, snapshotter string, containerName
defer ClearContainer(t, image, snapshotter, containerName)
}

containerMetic.E2ETime = time.Since(startTime)
containerMetric.E2ETime = time.Since(startTime)
if snapshotter == "nydus" {
backendMetrics, err := getContainerBackendMetrics(t)
if err != nil {
t.Logf(err.Error())
}
containerMetic.ReadAmountTotal = backendMetrics.ReadAmountTotal
containerMetic.ReadCount = backendMetrics.ReadCount
containerMetric.ReadAmountTotal = backendMetrics.ReadAmountTotal
containerMetric.ReadCount = backendMetrics.ReadCount
}

return &containerMetic
return &containerMetric
}

// RunContainerSimple just runs a container simply
Expand Down
14 changes: 7 additions & 7 deletions smoke/tests/tool/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *DescartesItem) GetUInt64(name string) uint64 {
// fmt.Println(item.Str())
// }
type DescartesIterator struct {
cursores []int
cursors []int
valLists [][]interface{}
cursorMap map[string]int
skip func(item *DescartesItem) bool
Expand All @@ -118,7 +118,7 @@ func (c *DescartesIterator) Next() *DescartesItem {
return nil
}

c.cursores = c.nextCursors
c.cursors = c.nextCursors
result := c.nextItem

c.clearNext()
Expand All @@ -133,8 +133,8 @@ func (c *DescartesIterator) HasNext() bool {

func (c *DescartesIterator) calNext() {

cursors := make([]int, len(c.cursores))
copy(cursors, c.cursores)
cursors := make([]int, len(c.cursors))
copy(cursors, c.cursors)

item := &DescartesItem{vals: make(map[string]interface{})}
for {
Expand Down Expand Up @@ -186,11 +186,11 @@ func (c *DescartesIterator) Dimension(name string, vals []interface{}) *Descarte
c.cursorMap = make(map[string]int)
}

c.cursores = append(c.cursores, 0)
c.cursors = append(c.cursors, 0)
c.valLists = append(c.valLists, vals)
c.cursorMap[name] = len(c.cursores) - 1
c.cursorMap[name] = len(c.cursors) - 1

c.cursores[0] = -1
c.cursors[0] = -1

return c
}
Expand Down
2 changes: 1 addition & 1 deletion smoke/tests/tool/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/pkg/errors"
)

// SnapshotterClient commnicates with nydus-snapshotter via
// SnapshotterClient communicates with nydus-snapshotter via
// the system controller endpoint unix socket of nydus-snapshotter.
type SnapshotterClient struct {
client *http.Client
Expand Down
4 changes: 2 additions & 2 deletions smoke/tests/tool/test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Generator func() (name string, testCase Case)
// asynchronous/synchronized control is suite-leveled.
//
// Compared with github.com/onsi/ginkgo, this framework provides simpler way to organize
// cases into suite, which requires less learing of terms and less nested definitions.
// cases into suite, which requires less learning of terms and less nested definitions.
// Moreover, the asynchronous run is more golang-natived, which requires no other binary.
//
// Compared with github.com/stretchr/testify, this framework provides asynchronous mode
Expand Down Expand Up @@ -161,7 +161,7 @@ type Generator func() (name string, testCase Case)
//
// `go test -v --parallel 4`
// 1. The cases are parallel executed, which leads to random completion.
// 2. The dynamic tests are named automicly in lack of customized name.
// 2. The dynamic tests are named automatically in lack of customized name.
//
// --- PASS: Test1 (0.00s)
// --- PASS: Test1/TestDynamicTest_4 (5.00s)
Expand Down

0 comments on commit 269831f

Please sign in to comment.