Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2e-523): inital commit - fixing e2e/system tests - WIP #535

Merged
merged 27 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6027c57
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
6af8480
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
69ff770
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
d90ac8f
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
872db19
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
f99699b
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
1dd6415
Merge branch 'main' into jose/test-folders-errors
mojtaba-esk Aug 12, 2024
041d471
chore: conflict resolve & some cleanup
mojtaba-esk Aug 12, 2024
98796b7
fix: linter complains
mojtaba-esk Aug 12, 2024
1bc549f
fix: minio concurrent bucket creation request issue
mojtaba-esk Aug 12, 2024
b2a8e98
fix: map init
mojtaba-esk Aug 12, 2024
03b5b5f
fix: kaniko concurrency overwriting issue
mojtaba-esk Aug 12, 2024
ba23bc9
chore: improve error propagation
mojtaba-esk Aug 13, 2024
8373c9d
fix: image cache issue fixed
mojtaba-esk Aug 16, 2024
845f7a9
fix: failing test suits removed problematic code
mojtaba-esk Aug 19, 2024
cd946d2
chore: increase system test timeout
mojtaba-esk Aug 19, 2024
9039336
chore: fix tests to be executed in parallel
mojtaba-esk Aug 19, 2024
83b02ab
chore: increase timeout to be on the safeside
mojtaba-esk Aug 20, 2024
05f32d1
chore: increase timeout to be on the safeside in the ci
mojtaba-esk Aug 20, 2024
f9d538f
chore: fixed the premature cleanup
mojtaba-esk Aug 20, 2024
29c4bba
chore: testing 60 min timeout
mojtaba-esk Aug 21, 2024
844acfc
fix: the deadlock issue in test suit
mojtaba-esk Aug 21, 2024
50e1ce1
chore: cleanup
mojtaba-esk Aug 21, 2024
6caa339
chore: fixed the missing cleanup
mojtaba-esk Aug 21, 2024
0c14000
chore: applied changes
mojtaba-esk Aug 22, 2024
de3fa64
chore: revert deletion of TestNoVolumesNoFiles
mojtaba-esk Aug 22, 2024
83a204a
Merge branch 'main' into jose/test-folders-errors
mojtaba-esk Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 73 additions & 27 deletions e2e/system/build_from_git_test.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
package system

import (
"bytes"
"context"
"strings"

"github.com/celestiaorg/knuu/pkg/builder"
)

const (
gitRepo = "https://github.com/celestiaorg/knuu.git"
gitBranch = "test/build-from-git" // This branch has a Dockerfile and is protected as to not be deleted
)

func (s *Suite) TestBuildFromGit() {
const namePrefix = "build-from-git"
s.T().Parallel()

// Setup
ctx := context.Background()

s.T().Log("Creating new instance")
target, err := s.Knuu.NewInstance(namePrefix)
s.Require().NoError(err)
if err != nil {
s.Require().NoError(err, "Error creating new instance")
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

s.T().Log("Building the image")

// This is a blocking call which builds the image from git repo
err = target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: "https://github.com/celestiaorg/knuu.git",
Branch: "test/build-from-git", // This branch has a Dockerfile and is protected as to not be deleted
Repo: gitRepo,
Branch: gitBranch,
Username: "",
Password: "",
})
s.Require().NoError(err)
s.Require().NoError(err, "Error setting git repo")

s.T().Log("Image built")

Expand All @@ -41,51 +50,88 @@ func (s *Suite) TestBuildFromGit() {
s.T().Logf("Starting instance")
s.Require().NoError(target.Execution().Start(ctx))

s.T().Logf("Instance started")
s.T().Log("Instance started")

s.T().Log("Getting file bytes")
// The file is created by the dockerfile in the repo,
// so to make sure it is built correctly, we check the file
data, err := target.Storage().GetFileBytes(ctx, "/test.txt")
s.Require().NoError(err)

data = []byte(strings.TrimSpace(string(data)))
s.Assert().Equal([]byte("Hello, World!"), data, "File bytes do not match")
if !bytes.Equal([]byte("Hello, World!"), data) {
s.Require().NoError(err, "File bytes do not match. Expected 'Hello, World!', got '%s'", string(data))
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

s.T().Log("Test completed successfully")
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved
}

func (s *Suite) TestBuildFromGitWithModifications() {
const namePrefix = "build-from-git-with-modifications"
const (
namePrefix = "build-from-git-with-modifications"
maxRetries = 3
)
s.T().Parallel()

// Setup
target, err := s.Knuu.NewInstance(namePrefix)
s.Require().NoError(err)

ctx := context.Background()
// This is a blocking call which builds the image from git repo
err = target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: "https://github.com/celestiaorg/knuu.git",
Branch: "test/build-from-git", // This branch has a Dockerfile and is protected as to not be deleted
Username: "",
Password: "",
})
s.Require().NoError(err)

s.Require().NoError(target.Build().SetStartCommand("sleep", "infinity"))

err = target.Storage().AddFileBytes([]byte("Hello, world!"), "/home/hello.txt", "root:root")
s.T().Log("Creating new instance")
target, err := s.Knuu.NewInstance(namePrefix)
if err != nil {
s.Require().NoError(err, "Error creating new instance")
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

s.T().Log("Setting git repo")
err = s.retryOperation(func() error {
return target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: gitRepo,
Branch: gitBranch,
Username: "",
Password: "",
})
}, maxRetries)
s.Require().NoError(err, "Error setting git repo")

s.T().Log("Setting command")
err = s.retryOperation(func() error {
return target.Build().SetStartCommand("sleep", "infinity")
}, maxRetries)
s.Require().NoError(err, "Error setting command")

s.T().Log("Adding file")
err = s.retryOperation(func() error {
return target.Storage().AddFileBytes([]byte("Hello, world!"), "/home/hello.txt", "root:root")
}, maxRetries)
s.Require().NoError(err, "Error adding file")

s.Require().NoError(target.Build().Commit(ctx))
s.T().Log("Committing changes")
err = s.retryOperation(func() error {
return target.Build().Commit(ctx)
}, maxRetries)
s.Require().NoError(err, "Error committing changes")

s.T().Cleanup(func() {
s.T().Log("Cleaning up instance")
if err := target.Execution().Destroy(ctx); err != nil {
s.T().Logf("Error cleaning up knuu: %v", err)
s.T().Logf("error destroying instance: %v", err)
}
})

s.Require().NoError(target.Execution().Start(ctx))
s.T().Log("Starting instance")
err = s.retryOperation(func() error {
return target.Execution().Start(ctx)
}, maxRetries)
s.Require().NoError(err, "Error starting instance")

data, err := target.Storage().GetFileBytes(ctx, "/home/hello.txt")
s.Require().NoError(err, "Error getting file bytes")
s.T().Log("Getting file bytes")
var data []byte
err = s.retryOperation(func() error {
var err error
data, err = target.Storage().GetFileBytes(ctx, "/home/hello.txt")
return err
}, maxRetries)

s.Assert().Equal([]byte("Hello, world!"), data, "File bytes do not match")
s.Require().NoError(err, "Error getting file bytes")
s.Assert().Equal([]byte("Hello, world!"), data, "file bytes do not match.")
}
69 changes: 52 additions & 17 deletions e2e/system/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,79 @@ import (
)

func (s *Suite) TestFile() {
const namePrefix = "file"
const (
namePrefix = "file"
maxRetries = 3
)
s.T().Parallel()
// Setup

// Setup
ctx := context.Background()

s.T().Log("Creating executor instance")
executor, err := s.Executor.NewInstance(ctx, namePrefix+"-executor")
s.Require().NoError(err)
if err != nil {
s.Require().NoError(err, "Error creating executor instance")
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

s.T().Log("Creating nginx instance with volume")
serverfile := s.createNginxInstanceWithVolume(ctx, namePrefix+"-serverfile")

err = serverfile.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
s.Require().NoError(err)
s.T().Log("Adding file to nginx instance")
err = s.retryOperation(func() error {
return serverfile.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
}, maxRetries)
s.Require().NoError(err, "Error adding file to nginx instance")

s.Require().NoError(serverfile.Build().Commit(ctx))
s.T().Log("Committing changes")
err = s.retryOperation(func() error {
return serverfile.Build().Commit(ctx)
}, maxRetries)
s.Require().NoError(err, "Error committing changes")

s.T().Cleanup(func() {
s.T().Log("Cleaning up instances")
err := instance.BatchDestroy(ctx, serverfile, executor)
if err != nil {
s.T().Logf("Error destroying instance: %v", err)
s.T().Logf("Error destroying instances: %v", err)
}
})

// Test logic

serverfileIP, err := serverfile.Network().GetIP(ctx)
s.Require().NoError(err)

s.Require().NoError(serverfile.Execution().Start(ctx))

wget, err := executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", serverfileIP)
s.Require().NoError(err)

s.T().Log("Getting server IP")
var serverfileIP string
err = s.retryOperation(func() error {
var err error
serverfileIP, err = serverfile.Network().GetIP(ctx)
return err
}, maxRetries)
s.Require().NoError(err, "Error getting server IP")

s.T().Log("Starting server")
err = s.retryOperation(func() error {
return serverfile.Execution().Start(ctx)
}, maxRetries)
s.Require().NoError(err, "Error starting server")

s.T().Log("Executing wget command")
var wget string
err = s.retryOperation(func() error {
var err error
wget, err = executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", serverfileIP)
return err
}, maxRetries)
s.Require().NoError(err, "Error executing wget command")

s.T().Log("Asserting wget output")
s.Assert().Contains(wget, "Hello World!")
}

func (s *Suite) TestDownloadFileFromRunningInstance() {
const namePrefix = "download-file-running"
const (
namePrefix = "download-file-running"
)
s.T().Parallel()

// Setup

target, err := s.Knuu.NewInstance(namePrefix + "-target")
Expand Down
47 changes: 36 additions & 11 deletions e2e/system/file_test_image_cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import (
)

func (s *Suite) TestFileCached() {
const namePrefix = "file-cached"
const (
namePrefix = "file-cached"
numberOfInstances = 10
maxRetries = 3
)
s.T().Parallel()

// Setup
ctx := context.Background()

executor, err := s.Executor.NewInstance(ctx, namePrefix+"-executor")
s.Require().NoError(err)

const numberOfInstances = 10
instances := make([]*instance.Instance, numberOfInstances)

instanceName := func(i int) string {
Expand All @@ -32,8 +37,10 @@ func (s *Suite) TestFileCached() {
wgFolders.Add(1)
go func(i int, instance *instance.Instance) {
defer wgFolders.Done()
err := s.retryOperation(func() error {
return instance.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
}, maxRetries)
// adding the folder after the Commit, it will help us to use a cached image.
err = instance.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
s.Require().NoError(err, "adding file to '%v'", instanceName(i))
}(i, ins)
}
Expand All @@ -49,19 +56,37 @@ func (s *Suite) TestFileCached() {

// Test logic
for _, i := range instances {
s.Require().NoError(i.Build().Commit(ctx))
s.Require().NoError(i.Execution().StartAsync(ctx))
err := s.retryOperation(func() error {
if err := i.Build().Commit(ctx); err != nil {
return fmt.Errorf("committing instance: %w", err)
}
if err := i.Execution().StartAsync(ctx); err != nil {
return fmt.Errorf("starting instance: %w", err)
}
return nil
}, maxRetries)
s.Require().NoError(err)
}

for _, i := range instances {
webIP, err := i.Network().GetIP(ctx)
s.Require().NoError(err)
err := s.retryOperation(func() error {
webIP, err := i.Network().GetIP(ctx)
if err != nil {
return fmt.Errorf("getting IP: %w", err)
}

s.Require().NoError(i.Execution().WaitInstanceIsRunning(ctx))
if err := i.Execution().WaitInstanceIsRunning(ctx); err != nil {
return fmt.Errorf("waiting for instance to run: %w", err)
}

wget, err := executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", webIP)
s.Require().NoError(err)
wget, err := executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", webIP)
if err != nil {
return fmt.Errorf("executing wget: %w", err)
}

s.Assert().Contains(wget, "Hello World!")
s.Assert().Contains(wget, "Hello World!")
return nil
}, maxRetries)
s.Require().NoError(err)
}
}
Loading
Loading