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 1 commit
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
56 changes: 43 additions & 13 deletions e2e/system/file_test_image_cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
import (
"context"
"fmt"
"strings"
"sync"
"time"

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

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

// Setup
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

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 +40,9 @@
wgFolders.Add(1)
go func(i int, instance *instance.Instance) {
defer wgFolders.Done()
// adding the folder after the Commit, it will help us to use a cached image.
err = instance.AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
err := s.retryOperation(func() error {

Check failure on line 43 in e2e/system/file_test_image_cached_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

s.retryOperation undefined (type *Suite has no field or method retryOperation)
return instance.AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
}, maxRetries)
tty47 marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err, "adding file to '%v'", instanceName(i))
}(i, ins)
}
Expand All @@ -49,19 +58,40 @@

// Test logic
for _, i := range instances {
s.Require().NoError(i.Commit())
s.Require().NoError(i.StartAsync(ctx))
err := s.retryOperation(func() error {

Check failure on line 61 in e2e/system/file_test_image_cached_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

s.retryOperation undefined (type *Suite has no field or method retryOperation)
if err := i.Commit(); err != nil {
return fmt.Errorf("committing instance: %w", err)
}
if err := i.StartAsync(ctx); err != nil {
return fmt.Errorf("starting instance: %w", err)
}
return nil
}, maxRetries)
tty47 marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err)
}

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

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

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

if !strings.Contains(wget, "Hello World!") {
return fmt.Errorf("expected 'Hello World!' in response, got: %s", wget)
}

s.Assert().Contains(wget, "Hello World!")
return nil
}, maxRetries)
s.Require().NoError(err)
}
}
76 changes: 28 additions & 48 deletions e2e/system/files_to_volumes_cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,13 @@
"fmt"
"strings"
"sync"
"time"

"k8s.io/apimachinery/pkg/api/resource"

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

// TestOneVolumeNoFiles tests the scenario where we have one volume and no files.
// the initContainer command that it generates looks like:
// no initContainer command, as there is no volumes, nor files.
func (s *Suite) TestNoVolumesNoFiles() {
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved
const namePrefix = "no-volumes-no-files"
s.T().Parallel()
// Setup

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

target := s.createNginxInstance(ctx, namePrefix+"-target")
s.Require().NoError(target.Commit())

// Cleanup
s.T().Cleanup(func() {
err := instance.BatchDestroy(ctx, executor, target)
if err != nil {
s.T().Logf("error destroying instance: %v", err)
}
})

// Test logic
s.Require().NoError(target.StartAsync(ctx))

webIP, err := target.GetIP(ctx)
s.Require().NoError(err)

s.Require().NoError(target.WaitInstanceIsRunning(ctx))

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

s.Assert().Contains(wget, "Welcome to nginx!")
}

// TestOneVolumeNoFiles tests the scenario where we have one volume and no files.
// the initContainer command that it generates looks like:
// mkdir -p /knuu && if [ -d /opt/vol1 ] && [ \"$(ls -A /opt/vol1)\" ]; then cp -r /opt/vol1/* /knuu//opt/vol1 && chown -R 0:0 /knuu/* ;fi
Expand Down Expand Up @@ -213,18 +177,20 @@
}
}

// TestOneVolumeOneFile tests the scenario where we have one volume and one file.
// TestOneVolumeTwoFiles tests the scenario where we have one volume and two files.
// the initContainer command that it generates looks like:
// mkdir -p /knuu && mkdir -p /knuu/usr/share/nginx/html && chmod -R 777 /knuu//usr/share/nginx/html && if [ -d /usr/share/nginx/html ] && [ \"$(ls -A /usr/share/nginx/html)\" ]; then cp -r /usr/share/nginx/html/* /knuu//usr/share/nginx/html && chown -R 0:0 /knuu/* ;fi
func (s *Suite) TestOneVolumeTwoFiles() {
const (
namePrefix = "one-volume-two-files"
numberOfInstances = 2
maxRetries = 3
)
s.T().Parallel()
// Setup

ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

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

Expand All @@ -240,12 +206,18 @@
wgFolders.Add(1)
go func(i *instance.Instance) {
defer wgFolders.Done()
// adding the folder after the Commit, it will help us to use a cached image.
err := i.AddFile(resourcesFileCMToFolder+"/test_1", nginxHTMLPath+"/index.html", "0:0")
s.Require().NoError(err, "adding file to '%v'", i.Name())

err = i.AddFile(resourcesFileCMToFolder+"/test_2", nginxHTMLPath+"/index-2.html", "0:0")
s.Require().NoError(err, "adding file to '%v'", i.Name())
err := s.retryOperation(func() error {

Check failure on line 209 in e2e/system/files_to_volumes_cm_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

s.retryOperation undefined (type *Suite has no field or method retryOperation) (typecheck)
err := i.AddFile(resourcesFileCMToFolder+"/test_1", nginxHTMLPath+"/index.html", "0:0")
if err != nil {
return fmt.Errorf("adding file to '%v': %w", i.Name(), err)
}
err = i.AddFile(resourcesFileCMToFolder+"/test_2", nginxHTMLPath+"/index-2.html", "0:0")
if err != nil {
return fmt.Errorf("adding file to '%v': %w", i.Name(), err)
}
return nil
}, maxRetries)
s.Require().NoError(err)
tty47 marked this conversation as resolved.
Show resolved Hide resolved
}(i)
}
wgFolders.Wait()
Expand All @@ -260,8 +232,16 @@

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

for _, i := range instances {
Expand Down
18 changes: 18 additions & 0 deletions e2e/system/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package system

import (
"fmt"
"time"
)

func retryOperation(operation func() error, maxRetries int) error {
var err error
for i := 0; i < maxRetries; i++ {
err = operation()
if err == nil {
return nil
}
time.Sleep(time.Second * time.Duration(i+1))
}
return fmt.Errorf("operation failed after %d retries: %w", maxRetries, err)
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved
Loading