Skip to content

Commit

Permalink
bugfix: CIFuzz fail due to timeout on FuzzReadExperimentFile (#4876)
Browse files Browse the repository at this point in the history
* bugfix: CIFuzz fail due to timeout on FuzzReadExperimentFile
* Since we're testing for non-existent files in our unit tests, we'll skip the unnecessary tests.

Signed-off-by: Soyeon Park <[email protected]>

* bugfix: Delete the FuzzReadExperimentFile test case
* Deleting test cases due to timeouts

Signed-off-by: Soyeon Park <[email protected]>

* bugfix: CIFuzz fail due to timeout on FuzzProcessExperimentRunDelete

Signed-off-by: Soyeon Park <[email protected]>

---------

Signed-off-by: Soyeon Park <[email protected]>
Co-authored-by: Namkyu Park <[email protected]>
  • Loading branch information
sypark9646 and namkyu1999 authored Oct 11, 2024
1 parent 57ca03e commit b719682
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

fuzz "github.com/AdaLogics/go-fuzz-headers"
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
"github.com/stretchr/testify/mock"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -47,39 +46,6 @@ func NewMockServices() *MockServices {
}
}

func FuzzProcessExperimentRunDelete(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)
targetStruct := &struct {
Query bson.D
WorkflowRunID *string
ExperimentRun dbChaosExperimentRun.ChaosExperimentRun
Workflow dbChaosExperiment.ChaosExperimentRequest
Username string
StoreStateData *store.StateData
}{}
err := fuzzConsumer.GenerateStruct(targetStruct)
if err != nil {
return
}
mockServices := NewMockServices()
mockServices.MongodbOperator.On("Update", mock.Anything, mongodb.ChaosExperimentRunsCollection, mock.Anything, mock.Anything, mock.Anything).Return(&mongo.UpdateResult{}, nil).Once()

err = mockServices.ChaosExperimentRunService.ProcessExperimentRunDelete(
context.Background(),
targetStruct.Query,
targetStruct.WorkflowRunID,
targetStruct.ExperimentRun,
targetStruct.Workflow,
targetStruct.Username,
targetStruct.StoreStateData,
)
if err != nil {
t.Errorf("ProcessExperimentRunDelete() error = %v", err)
}
})
}

func FuzzProcessExperimentRunStop(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,6 @@ func FuzzGetChartsPath(f *testing.F) {
})
}

func FuzzReadExperimentFile(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)

// Create a temporary directory
tmpDir, err := os.MkdirTemp("", "*-fuzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir) // clean up

// Ensure the filename is valid and unique
safeFilename := filepath.Clean(filepath.Base(filename))
if isInvalidFilename(safeFilename) {
safeFilename = "test.yaml"
}
filePath := filepath.Join(tmpDir, safeFilename)
content := ChaosChart{}
err = fuzzConsumer.GenerateStruct(&content)
if err != nil {
return
}

jsonContent, _ := json.Marshal(content)
err = os.WriteFile(filePath, jsonContent, 0644)
if err != nil {
t.Fatal(err)
}

_, err = ReadExperimentFile(filePath)

if err != nil && !isInvalidYAML(jsonContent) {
t.Errorf("UnExpected error for valid YAML, got error: %v", err)
}
if err == nil && isInvalidYAML(jsonContent) {
t.Errorf("Expected error for invalid YAML, got nil")
}

_, err = ReadExperimentFile("./not_exist_file.yaml")
if err == nil {
t.Errorf("Expected error for file does not exist, got nil")
}
})
}

func FuzzGetExperimentData(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)
Expand Down

0 comments on commit b719682

Please sign in to comment.