Skip to content

Commit d735449

Browse files
nosnelmilleokondrashov
authored andcommitted
update tests
Signed-off-by: Lenson <nosnelmil@gmail.com> update multi loader e2e tests Signed-off-by: Lenson <nosnelmil@gmail.com> revert setup.cfg Signed-off-by: Lenson <nosnelmil@gmail.com> chmod script Signed-off-by: Lenson <nosnelmil@gmail.com> update unit tests Signed-off-by: Lenson <nosnelmil@gmail.com> fix e2e test Signed-off-by: Lenson <nosnelmil@gmail.com> update tests Signed-off-by: Lenson <nosnelmil@gmail.com>
1 parent 316c488 commit d735449

18 files changed

+103
-162
lines changed

.github/workflows/e2e_loader.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Checkout repository
3333
uses: actions/checkout@v4
3434

35-
- name: Set up Kubernetes Kind Cluster
35+
- name: Set up Kubernetes KinD Cluster and install Knative
3636
uses: ./.github/actions/ci_knative_setup
3737

3838
- name: Build and run loader

.github/workflows/e2e_multi_loader.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@ jobs:
2323
runs-on: ubuntu-20.04
2424
strategy:
2525
fail-fast: false
26-
matrix:
27-
service:
28-
[
29-
trace_func_go,
30-
]
3126
steps:
3227
- name: Checkout repository
3328
uses: actions/checkout@v4
3429

35-
- name: Set up Kubernetes Kind Cluster
30+
- name: Set up Kubernetes KinD Cluster and install Knative
3631
uses: ./.github/actions/ci_knative_setup
32+
33+
- name: Setup traces for multi trace test
34+
shell: bash
35+
run: bash ./scripts/setup/setup_multi_test_trace.sh
3736

3837
- name: Build and run multi-loader
3938
run: go run tools/multi_loader/multi_loader.go --multiLoaderConfigPath tools/multi_loader/multi_loader_config.json
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Duplicate example traces to make multi traces
4+
mkdir -p data/multi_traces/
5+
cp -r data/traces/example data/multi_traces/example_1_test
6+
cp -r data/traces/example data/multi_traces/example_2_test
7+
cp -r data/traces/example data/multi_traces/example_3.1_test

tools/multi_loader/base_loader_config.json

-23
This file was deleted.

tools/multi_loader/multi_loader_config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"Generated": false,
1010
"Verbosity": "info",
1111
"TracesDir": "",
12-
"TracesFormat": "tools/multi_loader/test_data/example_{}_test",
12+
"TracesFormat": "data/multi_traces/example_{}_test",
1313
"TraceValues": [
1414
"1",
1515
"2",
@@ -22,5 +22,5 @@
2222
],
2323
"PreScript": "",
2424
"PostScript": "",
25-
"BaseConfigPath": "tools/multi_loader/base_loader_config.json"
25+
"BaseConfigPath": "pkg/config/test_config.json"
2626
}

tools/multi_loader/runner/multi_loader_runner_test.go

+88-70
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package runner
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
7+
"path"
68
"path/filepath"
79
"strings"
810
"testing"
@@ -16,62 +18,20 @@ import (
1618
var (
1719
multiLoaderTestConfigPath string
1820
configPath string
21+
rootPath string
1922
)
2023

2124
func init() {
2225
wd, _ := os.Getwd()
23-
multiLoaderTestConfigPath = filepath.Join(wd, "../multi_loader_config.json")
24-
configPath = filepath.Join(wd, "../base_loader_config.json")
25-
log.Info("Test config path: ", multiLoaderTestConfigPath)
26-
log.Info("Test config path: ", configPath)
27-
28-
// Override the BaseConfigPath field in multi_loader_config.json
29-
mlConfig := ml_common.ReadMultiLoaderConfigurationFile(multiLoaderTestConfigPath)
30-
mlConfig.BaseConfigPath = "../base_loader_config.json"
31-
multiLoaderTestConfigPath = "../multi_loader_config_test.json"
32-
ml_common.WriteMultiLoaderConfigurationFile(mlConfig, multiLoaderTestConfigPath)
26+
rootPath = path.Join(wd, "..", "..", "..")
3327
}
3428

3529
func TestUnpackExperiment(t *testing.T) {
36-
// helper func to validate unpacked experiments
37-
validateUnpackedExperiment := func(t *testing.T, experimentConfig []types.LoaderExperiment, studyConfig types.LoaderStudy, expectedNames []string, expectedOutputPrefixes []string) {
38-
if len(experimentConfig) != len(expectedNames) {
39-
t.Errorf("Expected %d sub-experiments, got %d", len(expectedNames), len(experimentConfig))
40-
return
41-
}
42-
43-
for i, subExp := range experimentConfig {
44-
// check name
45-
if subExp.Name != expectedNames[i] {
46-
t.Errorf("Expected subexperiment name '%s', got '%s'", expectedNames[i], subExp.Name)
47-
}
48-
49-
// validate selected configs
50-
if subExp.Config["ExperimentDuration"] != studyConfig.Config["ExperimentDuration"] {
51-
t.Errorf("Expected ExperimentDuration %v, got %v", studyConfig.Config["ExperimentDuration"], subExp.Config["ExperimentDuration"])
52-
}
53-
if subExp.OutputDir != studyConfig.OutputDir {
54-
t.Errorf("Expected OutputDir '%s', got '%s'", studyConfig.OutputDir, subExp.OutputDir)
55-
}
56-
57-
// check OutputPathPrefix if needed
58-
if len(expectedOutputPrefixes) > 0 {
59-
if outputPathPrefix, ok := subExp.Config["OutputPathPrefix"].(string); !(ok && strings.HasSuffix(outputPathPrefix, expectedOutputPrefixes[i])) {
60-
t.Errorf("Expected OutputPathPrefix '%s', got '%s'", expectedOutputPrefixes[i], subExp.Config["OutputPathPrefix"])
61-
}
62-
}
63-
}
64-
}
65-
66-
// create multiloader
67-
multiLoader, err := NewMultiLoaderRunner(multiLoaderTestConfigPath, "info", false, false, false)
68-
if err != nil {
69-
t.Fatalf("Failed to create multi-loader driver: %v", err)
70-
}
71-
30+
cleanup, multiLoader := setup()
31+
defer cleanup()
7232
t.Run("Unpack using TracesDir (Success)", func(t *testing.T) {
7333
// Set TracesDir to test directory
74-
multiLoader.MultiLoaderConfig.Studies[0].TracesDir = "../test_data"
34+
multiLoader.MultiLoaderConfig.Studies[0].TracesDir = path.Join(rootPath, "data", "multi_traces")
7535

7636
for _, experiment := range multiLoader.MultiLoaderConfig.Studies {
7737
subExperiments := multiLoader.unpackStudy(experiment)
@@ -117,17 +77,13 @@ func TestUnpackExperiment(t *testing.T) {
11777
}
11878

11979
func TestPrepareExperiment(t *testing.T) {
120-
// Create a new multi-loader driver with the test config path
121-
multiLoader, err := NewMultiLoaderRunner(multiLoaderTestConfigPath, "info", false, false, false)
122-
if err != nil {
123-
t.Fatalf("Failed to create multi-loader driver: %v", err)
124-
}
125-
80+
cleanup, multiLoader := setup()
81+
defer cleanup()
12682
subExperiment := types.LoaderExperiment{
12783
Name: "example_1",
12884
Config: map[string]interface{}{
12985
"ExperimentDuration": 10,
130-
"TracePath": "../test_data/example_1_test",
86+
"TracePath": path.Join(rootPath, "data", "multi_traces", "example_1_test"),
13187
"OutputPathPrefix": "./test_output/example_1_test",
13288
},
13389
}
@@ -158,23 +114,22 @@ func TestPrepareExperiment(t *testing.T) {
158114

159115
// Test mergeConfigurations method
160116
func TestMergeConfig(t *testing.T) {
161-
// Create a new multi-loader driver with the test config path
162-
multiLoader, err := NewMultiLoaderRunner(multiLoaderTestConfigPath, "info", false, false, false)
163-
if err != nil {
164-
t.Fatalf("Failed to create multi-loader driver: %v", err)
165-
}
117+
cleanup, multiLoader := setup()
118+
defer cleanup()
119+
120+
newTracePath := path.Join(rootPath, "data", "multi_traces", "example_1_test")
166121
experiment := types.LoaderExperiment{
167122
Name: "example_1",
168123
Config: map[string]interface{}{
169124
"ExperimentDuration": 10,
170-
"TracePath": "../test_data/example_1_test",
125+
"TracePath": newTracePath,
171126
"OutputPathPrefix": "./test_output/example_1_test",
172127
},
173128
}
174129
outputConfig := multiLoader.mergeConfigurations(configPath, experiment)
175130
// Check if the configurations are merged
176-
if outputConfig.TracePath != "../test_data/example_1_test" {
177-
t.Errorf("Expected TracePath to be '../test_data/example_1_test', got %v", experiment.Config["TracePath"])
131+
if outputConfig.TracePath != newTracePath {
132+
t.Errorf("Expected TracePath to be '%v', got %v", newTracePath, experiment.Config["TracePath"])
178133
}
179134
if outputConfig.OutputPathPrefix != "./test_output/example_1_test" {
180135
t.Errorf("Expected OutputPathPrefix to be './test_output/example_1_test', got %v", experiment.Config["OutputPathPrefix"])
@@ -185,11 +140,8 @@ func TestMergeConfig(t *testing.T) {
185140
}
186141

187142
func TestMultiConfigValidator(t *testing.T) {
188-
// Create a new multi-loader driver with the test config path
189-
multiLoader, err := NewMultiLoaderRunner(multiLoaderTestConfigPath, "info", false, false, false)
190-
if err != nil {
191-
t.Fatalf("Failed to create multi-loader driver: %v", err)
192-
}
143+
cleanup, multiLoader := setup()
144+
defer cleanup()
193145
t.Run("CheckMultiLoaderConfig (Success)", func(t *testing.T) {
194146
// Check if all paths are valid
195147
ml_common.CheckMultiLoaderConfig(multiLoader.MultiLoaderConfig)
@@ -237,15 +189,81 @@ func TestMultiConfigValidator(t *testing.T) {
237189
})
238190
}
239191

192+
func setup() (func(), MultiLoaderRunner) {
193+
wd, _ := os.Getwd()
194+
multiLoaderTestConfigPath = filepath.Join(wd, "../multi_loader_config.json")
195+
configPath = filepath.Join(rootPath, "pkg/config/test_config.json")
196+
log.Info("Test config path: ", multiLoaderTestConfigPath)
197+
log.Info("Test config path: ", configPath)
198+
199+
// Override the BaseConfigPath field in multi_loader_config.json
200+
mlConfig := ml_common.ReadMultiLoaderConfigurationFile(multiLoaderTestConfigPath)
201+
mlConfig.BaseConfigPath = filepath.Join(rootPath, "pkg/config/test_config.json")
202+
multiLoaderTestConfigPath = "../multi_loader_config_test.json"
203+
ml_common.WriteMultiLoaderConfigurationFile(mlConfig, multiLoaderTestConfigPath)
204+
205+
// Create test_data
206+
filePath := filepath.Join(rootPath, "scripts", "setup", "setup_multi_test_trace.sh")
207+
cmd := exec.Command("bash", filePath)
208+
cmd.Dir = rootPath
209+
out, err := cmd.CombinedOutput()
210+
if err != nil {
211+
log.Fatal("Failed to create test traces:", string(out), err)
212+
}
213+
214+
cleanup := func() {
215+
os.Remove(multiLoaderTestConfigPath)
216+
os.RemoveAll(path.Join(rootPath, "data", "multi_traces"))
217+
}
218+
219+
// Create a new multi-loader driver with the test config path
220+
multiLoader, err := NewMultiLoaderRunner(multiLoaderTestConfigPath, "info", false, false, false)
221+
if err != nil {
222+
log.Fatalf("Failed to create multi-loader driver: %v", err)
223+
}
224+
225+
return cleanup, *multiLoader
226+
}
227+
228+
// helper func to validate unpacked experiments
229+
func validateUnpackedExperiment(t *testing.T, experimentConfig []types.LoaderExperiment, studyConfig types.LoaderStudy, expectedNames []string, expectedOutputPrefixes []string) {
230+
if len(experimentConfig) != len(expectedNames) {
231+
t.Errorf("Expected %d sub-experiments, got %d", len(expectedNames), len(experimentConfig))
232+
return
233+
}
234+
235+
for i, subExp := range experimentConfig {
236+
// check name
237+
if subExp.Name != expectedNames[i] {
238+
t.Errorf("Expected subexperiment name '%s', got '%s'", expectedNames[i], subExp.Name)
239+
}
240+
241+
// validate selected configs
242+
if subExp.Config["ExperimentDuration"] != studyConfig.Config["ExperimentDuration"] {
243+
t.Errorf("Expected ExperimentDuration %v, got %v", studyConfig.Config["ExperimentDuration"], subExp.Config["ExperimentDuration"])
244+
}
245+
if subExp.OutputDir != studyConfig.OutputDir {
246+
t.Errorf("Expected OutputDir '%s', got '%s'", studyConfig.OutputDir, subExp.OutputDir)
247+
}
248+
249+
// check OutputPathPrefix if needed
250+
if len(expectedOutputPrefixes) > 0 {
251+
if outputPathPrefix, ok := subExp.Config["OutputPathPrefix"].(string); !(ok && strings.HasSuffix(outputPathPrefix, expectedOutputPrefixes[i])) {
252+
t.Errorf("Expected OutputPathPrefix '%s', got '%s'", expectedOutputPrefixes[i], subExp.Config["OutputPathPrefix"])
253+
}
254+
}
255+
}
256+
}
257+
240258
func expectFatal(t *testing.T, funcToTest func()) {
241259
fatal := false
242260
originalExitFunc := log.StandardLogger().ExitFunc
243-
244-
// replace logrus exit function
261+
log.Info("Expecting a fatal message during the test, overriding the exit function")
262+
// Replace logrus exit function
245263
log.StandardLogger().ExitFunc = func(int) { fatal = true }
246264

247265
funcToTest()
248-
// restore original state
266+
// Restore original exit function
249267
log.StandardLogger().ExitFunc = originalExitFunc
250268
assert.True(t, fatal, "Expected log.Fatal to be called")
251269
}

tools/multi_loader/test_data/example_1_test/dirigent.csv

-5
This file was deleted.

tools/multi_loader/test_data/example_1_test/durations.csv

-5
This file was deleted.

0 commit comments

Comments
 (0)