Skip to content

Commit b719682

Browse files
bugfix: CIFuzz fail due to timeout on FuzzReadExperimentFile (#4876)
* 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]>
1 parent 57ca03e commit b719682

File tree

2 files changed

+0
-79
lines changed

2 files changed

+0
-79
lines changed

chaoscenter/graphql/server/pkg/chaos_experiment_run/fuzz_tests/service_fuzz_test.go

-34
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
fuzz "github.com/AdaLogics/go-fuzz-headers"
1414
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store"
15-
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
1615
"github.com/stretchr/testify/mock"
1716
"go.mongodb.org/mongo-driver/bson"
1817
"go.mongodb.org/mongo-driver/mongo"
@@ -47,39 +46,6 @@ func NewMockServices() *MockServices {
4746
}
4847
}
4948

50-
func FuzzProcessExperimentRunDelete(f *testing.F) {
51-
f.Fuzz(func(t *testing.T, data []byte) {
52-
fuzzConsumer := fuzz.NewConsumer(data)
53-
targetStruct := &struct {
54-
Query bson.D
55-
WorkflowRunID *string
56-
ExperimentRun dbChaosExperimentRun.ChaosExperimentRun
57-
Workflow dbChaosExperiment.ChaosExperimentRequest
58-
Username string
59-
StoreStateData *store.StateData
60-
}{}
61-
err := fuzzConsumer.GenerateStruct(targetStruct)
62-
if err != nil {
63-
return
64-
}
65-
mockServices := NewMockServices()
66-
mockServices.MongodbOperator.On("Update", mock.Anything, mongodb.ChaosExperimentRunsCollection, mock.Anything, mock.Anything, mock.Anything).Return(&mongo.UpdateResult{}, nil).Once()
67-
68-
err = mockServices.ChaosExperimentRunService.ProcessExperimentRunDelete(
69-
context.Background(),
70-
targetStruct.Query,
71-
targetStruct.WorkflowRunID,
72-
targetStruct.ExperimentRun,
73-
targetStruct.Workflow,
74-
targetStruct.Username,
75-
targetStruct.StoreStateData,
76-
)
77-
if err != nil {
78-
t.Errorf("ProcessExperimentRunDelete() error = %v", err)
79-
}
80-
})
81-
}
82-
8349
func FuzzProcessExperimentRunStop(f *testing.F) {
8450
f.Fuzz(func(t *testing.T, data []byte) {
8551
fuzzConsumer := fuzz.NewConsumer(data)

chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go

-45
Original file line numberDiff line numberDiff line change
@@ -41,51 +41,6 @@ func FuzzGetChartsPath(f *testing.F) {
4141
})
4242
}
4343

44-
func FuzzReadExperimentFile(f *testing.F) {
45-
f.Fuzz(func(t *testing.T, data []byte, filename string) {
46-
fuzzConsumer := fuzz.NewConsumer(data)
47-
48-
// Create a temporary directory
49-
tmpDir, err := os.MkdirTemp("", "*-fuzztest")
50-
if err != nil {
51-
t.Fatal(err)
52-
}
53-
defer os.RemoveAll(tmpDir) // clean up
54-
55-
// Ensure the filename is valid and unique
56-
safeFilename := filepath.Clean(filepath.Base(filename))
57-
if isInvalidFilename(safeFilename) {
58-
safeFilename = "test.yaml"
59-
}
60-
filePath := filepath.Join(tmpDir, safeFilename)
61-
content := ChaosChart{}
62-
err = fuzzConsumer.GenerateStruct(&content)
63-
if err != nil {
64-
return
65-
}
66-
67-
jsonContent, _ := json.Marshal(content)
68-
err = os.WriteFile(filePath, jsonContent, 0644)
69-
if err != nil {
70-
t.Fatal(err)
71-
}
72-
73-
_, err = ReadExperimentFile(filePath)
74-
75-
if err != nil && !isInvalidYAML(jsonContent) {
76-
t.Errorf("UnExpected error for valid YAML, got error: %v", err)
77-
}
78-
if err == nil && isInvalidYAML(jsonContent) {
79-
t.Errorf("Expected error for invalid YAML, got nil")
80-
}
81-
82-
_, err = ReadExperimentFile("./not_exist_file.yaml")
83-
if err == nil {
84-
t.Errorf("Expected error for file does not exist, got nil")
85-
}
86-
})
87-
}
88-
8944
func FuzzGetExperimentData(f *testing.F) {
9045
f.Fuzz(func(t *testing.T, data []byte, filename string) {
9146
fuzzConsumer := fuzz.NewConsumer(data)

0 commit comments

Comments
 (0)