-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
smoke: add smoking test for cas and chunk dedup
Add smoking test case for cas and chunk dedup. Signed-off-by: Yadong Ding <[email protected]>
- Loading branch information
1 parent
b9ba409
commit 57c112a
Showing
12 changed files
with
314 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// Copyright 2024 Nydus Developers. All rights reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package tests | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
_ "github.com/mattn/go-sqlite3" | ||
|
||
"github.com/dragonflyoss/nydus/smoke/tests/texture" | ||
"github.com/dragonflyoss/nydus/smoke/tests/tool" | ||
"github.com/dragonflyoss/nydus/smoke/tests/tool/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type CasTestSuite struct{} | ||
|
||
func (c *CasTestSuite) TestCasTables() test.Generator { | ||
scenarios := tool.DescartesIterator{} | ||
scenarios.Dimension(paramEnablePrefetch, []interface{}{false, true}) | ||
|
||
return func() (name string, testCase test.Case) { | ||
if !scenarios.HasNext() { | ||
return | ||
} | ||
scenario := scenarios.Next() | ||
|
||
return scenario.Str(), func(t *testing.T) { | ||
c.testCasTables(t, scenario.GetBool(paramEnablePrefetch)) | ||
} | ||
} | ||
} | ||
|
||
func (c *CasTestSuite) testCasTables(t *testing.T, enablePrefetch bool) { | ||
ctx, layer := texture.PrepareLayerWithContext(t) | ||
ctx.Runtime.EnablePrefetch = enablePrefetch | ||
ctx.Runtime.ChunkDedupDb = filepath.Join(ctx.Env.WorkDir, "cas.db") | ||
|
||
nydusd, err := tool.NewNydusdWithContext(*ctx) | ||
require.NoError(t, err) | ||
err = nydusd.Mount() | ||
require.NoError(t, err) | ||
defer nydusd.Umount() | ||
nydusd.Verify(t, layer.FileTree) | ||
|
||
db, err := sql.Open("sqlite3", ctx.Runtime.ChunkDedupDb) | ||
require.NoError(t, err) | ||
defer db.Close() | ||
|
||
for _, expectedTable := range []string{"Blobs", "Chunks"} { | ||
// Manual execution WAL Checkpoint | ||
_, err = db.Exec("PRAGMA wal_checkpoint(FULL)") | ||
require.NoError(t, err) | ||
var count int | ||
query := fmt.Sprintf("SELECT COUNT(*) FROM %s;", expectedTable) | ||
err = db.QueryRow(query).Scan(&count) | ||
require.NoError(t, err) | ||
if expectedTable == "Blobs" { | ||
require.Equal(t, 1, count) | ||
} else { | ||
require.Equal(t, 8, count) | ||
} | ||
} | ||
} | ||
|
||
func (c *CasTestSuite) TestCasGcUmountByAPI() test.Generator { | ||
scenarios := tool.DescartesIterator{} | ||
scenarios.Dimension(paramEnablePrefetch, []interface{}{false, true}) | ||
|
||
return func() (name string, testCase test.Case) { | ||
if !scenarios.HasNext() { | ||
return | ||
} | ||
scenario := scenarios.Next() | ||
|
||
return scenario.Str(), func(t *testing.T) { | ||
c.testCasGcUmountByAPI(t, scenario.GetBool(paramEnablePrefetch)) | ||
} | ||
} | ||
} | ||
|
||
func (c *CasTestSuite) testCasGcUmountByAPI(t *testing.T, enablePrefetch bool) { | ||
ctx, layer := texture.PrepareLayerWithContext(t) | ||
defer ctx.Destroy(t) | ||
|
||
config := tool.NydusdConfig{ | ||
NydusdPath: ctx.Binary.Nydusd, | ||
MountPath: ctx.Env.MountDir, | ||
APISockPath: filepath.Join(ctx.Env.WorkDir, "nydusd-api.sock"), | ||
ConfigPath: filepath.Join(ctx.Env.WorkDir, "nydusd-config.fusedev.json"), | ||
ChunkDedupDb: filepath.Join(ctx.Env.WorkDir, "cas.db"), | ||
} | ||
nydusd, err := tool.NewNydusd(config) | ||
require.NoError(t, err) | ||
|
||
err = nydusd.Mount() | ||
defer nydusd.Umount() | ||
require.NoError(t, err) | ||
|
||
config.BootstrapPath = ctx.Env.BootstrapPath | ||
config.MountPath = "/mount" | ||
config.BackendType = "localfs" | ||
config.BackendConfig = fmt.Sprintf(`{"dir": "%s"}`, ctx.Env.BlobDir) | ||
config.BlobCacheDir = ctx.Env.CacheDir | ||
config.CacheType = ctx.Runtime.CacheType | ||
config.CacheCompressed = ctx.Runtime.CacheCompressed | ||
config.RafsMode = ctx.Runtime.RafsMode | ||
config.EnablePrefetch = enablePrefetch | ||
config.DigestValidate = false | ||
config.AmplifyIO = ctx.Runtime.AmplifyIO | ||
err = nydusd.MountByAPI(config) | ||
require.NoError(t, err) | ||
|
||
nydusd.VerifyByPath(t, layer.FileTree, config.MountPath) | ||
|
||
db, err := sql.Open("sqlite3", config.ChunkDedupDb) | ||
require.NoError(t, err) | ||
defer db.Close() | ||
|
||
for _, expectedTable := range []string{"Blobs", "Chunks"} { | ||
_, err = db.Exec("PRAGMA wal_checkpoint(FULL)") | ||
require.NoError(t, err) | ||
var count int | ||
query := fmt.Sprintf("SELECT COUNT(*) FROM %s;", expectedTable) | ||
err := db.QueryRow(query).Scan(&count) | ||
require.NoError(t, err) | ||
require.NotZero(t, count) | ||
} | ||
|
||
// Mock nydus snapshotter clear cache | ||
os.RemoveAll(filepath.Join(ctx.Env.WorkDir, "cache")) | ||
time.Sleep(1 * time.Second) | ||
|
||
nydusd.UmountByAPI(config.MountPath) | ||
|
||
for _, expectedTable := range []string{"Blobs", "Chunks"} { | ||
_, err = db.Exec("PRAGMA wal_checkpoint(FULL)") | ||
require.NoError(t, err) | ||
var count int | ||
query := fmt.Sprintf("SELECT COUNT(*) FROM %s;", expectedTable) | ||
err := db.QueryRow(query).Scan(&count) | ||
require.NoError(t, err) | ||
require.Zero(t, count) | ||
} | ||
} | ||
|
||
func TestCas(t *testing.T) { | ||
test.Run(t, &CasTestSuite{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2024 Nydus Developers. All rights reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package tests | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/dragonflyoss/nydus/smoke/tests/texture" | ||
"github.com/dragonflyoss/nydus/smoke/tests/tool" | ||
"github.com/dragonflyoss/nydus/smoke/tests/tool/test" | ||
) | ||
|
||
const ( | ||
paramIteration = "iteration" | ||
) | ||
|
||
type ChunkDedupTestSuite struct{} | ||
|
||
func (c *ChunkDedupTestSuite) TestChunkDedup() test.Generator { | ||
scenarios := tool.DescartesIterator{} | ||
scenarios.Dimension(paramIteration, []interface{}{1}) | ||
|
||
file, err := os.CreateTemp("", "cas-*.db") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer os.Remove(file.Name()) | ||
|
||
return func() (name string, testCase test.Case) { | ||
if !scenarios.HasNext() { | ||
return | ||
} | ||
scenario := scenarios.Next() | ||
|
||
return scenario.Str(), func(t *testing.T) { | ||
c.testRemoteWithDedup(t, file.Name()) | ||
} | ||
} | ||
} | ||
|
||
func (c *ChunkDedupTestSuite) testRemoteWithDedup(t *testing.T, dbPath string) { | ||
ctx, layer := texture.PrepareLayerWithContext(t) | ||
defer ctx.Destroy(t) | ||
ctx.Runtime.EnablePrefetch = false | ||
ctx.Runtime.ChunkDedupDb = dbPath | ||
|
||
nydusd, err := tool.NewNydusdWithContext(*ctx) | ||
require.NoError(t, err) | ||
err = nydusd.Mount() | ||
require.NoError(t, err) | ||
defer nydusd.Umount() | ||
nydusd.Verify(t, layer.FileTree) | ||
metrics, err := nydusd.GetBackendMetrics() | ||
require.NoError(t, err) | ||
require.Zero(t, metrics.ReadErrors) | ||
|
||
ctx2, layer2 := texture.PrepareLayerWithContext(t) | ||
defer ctx2.Destroy(t) | ||
ctx2.Runtime.EnablePrefetch = false | ||
ctx2.Runtime.ChunkDedupDb = dbPath | ||
|
||
nydusd2, err := tool.NewNydusdWithContext(*ctx2) | ||
require.NoError(t, err) | ||
err = nydusd2.Mount() | ||
require.NoError(t, err) | ||
defer nydusd2.Umount() | ||
nydusd2.Verify(t, layer2.FileTree) | ||
metrics2, err := nydusd2.GetBackendMetrics() | ||
require.NoError(t, err) | ||
require.Zero(t, metrics2.ReadErrors) | ||
|
||
require.Greater(t, metrics.ReadCount, metrics2.ReadCount) | ||
require.Greater(t, metrics.ReadAmountTotal, metrics2.ReadAmountTotal) | ||
} | ||
|
||
func TestChunkDedup(t *testing.T) { | ||
test.Run(t, &ChunkDedupTestSuite{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.