Skip to content

Commit 37eeb9a

Browse files
committed
chore: capture profile data from integration test
🔒 Scanned for secrets using gitleaks 8.30.0
1 parent 40aa461 commit 37eeb9a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ workspaceConfig.json
1010
imports/enterprise.go
1111
*.coverprofile
1212
junit*.xml
13-
**/profile.out
13+
**/*profile.out
1414
**/*.test
1515
.idea/*
1616
build/regulation-worker

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ test-teardown:
6565
echo "Tests passed, tearing down..." ;\
6666
rm -f $(TESTFILE) ;\
6767
echo "mode: atomic" > coverage.txt ;\
68-
find . -name "profile.out" | while read file; do grep -v 'mode: atomic' $${file} >> coverage.txt; rm -f $${file}; done ;\
68+
find . -name "*profile.out" | while read file; do grep -Ev 'mode: atomic|mode: set' $${file} >> coverage.txt; rm -f $${file}; done ;\
6969
else \
70-
rm -f coverage.txt coverage.html ; find . -name "profile.out" | xargs rm -f ;\
70+
rm -f coverage.txt coverage.html ; find . -name "*profile.out" | xargs rm -f ;\
7171
echo "Tests failed :-(" ;\
7272
exit 1 ;\
7373
fi

integration_test/partitionmigration/partitionmigration_embedded_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestPartitionMigrationEmbeddedMode(t *testing.T) {
161161
rsBinaryPath := filepath.Join(t.TempDir(), "rudder-server-binary")
162162
buildRudderServerBinary(t, rsBinaryPath)
163163
node0Name := "node-0"
164-
startRudderServer(ctx, g, node0Name, rsBinaryPath, lo.Assign(commonEnv, map[string]string{
164+
startRudderServer(t, ctx, g, node0Name, rsBinaryPath, lo.Assign(commonEnv, map[string]string{
165165
"PROCESSOR_INDEX": "0",
166166
"HOSTNAME": node0Name,
167167
"INSTANCE_ID": node0Name,
@@ -182,7 +182,7 @@ func TestPartitionMigrationEmbeddedMode(t *testing.T) {
182182
)
183183

184184
node1Name := "node-1"
185-
startRudderServer(ctx, g, node1Name, rsBinaryPath, lo.Assign(commonEnv, map[string]string{
185+
startRudderServer(t, ctx, g, node1Name, rsBinaryPath, lo.Assign(commonEnv, map[string]string{
186186
"PROCESSOR_INDEX": "1",
187187
"HOSTNAME": node1Name,
188188
"INSTANCE_ID": node1Name,

integration_test/partitionmigration/rudderserver_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// buildRudderServerBinary builds the rudder-server binary and returns its path.
1818
func buildRudderServerBinary(t *testing.T, binaryPath string) {
1919
name := "testbinary"
20-
buildCmd := exec.Command("go", "build", "-o", binaryPath, "../../main.go")
20+
buildCmd := exec.Command("go", "build", "-cover", "-o", binaryPath, "../../main.go")
2121
buildCmd.Stderr = os.Stderr
2222
buildCmd.Stdout = os.Stdout
2323
if err := buildCmd.Run(); err != nil {
@@ -26,8 +26,10 @@ func buildRudderServerBinary(t *testing.T, binaryPath string) {
2626
}
2727

2828
// startRudderServer starts a rudder-server process with the given environment configuration in a separate goroutine managed by the provided errgroup.Group.
29-
func startRudderServer(ctx context.Context, g *errgroup.Group, name, binaryPath string, configs map[string]string) {
29+
func startRudderServer(t *testing.T, ctx context.Context, g *errgroup.Group, name, binaryPath string, configs map[string]string) {
3030
g.Go(func() error {
31+
coverDir := t.TempDir()
32+
configs["GOCOVERDIR"] = coverDir
3133
cmd := exec.CommandContext(ctx, binaryPath)
3234
cmd.Env = append(os.Environ(), lo.MapToSlice(configs, func(k, v string) string {
3335
return config.ConfigKeyToEnv(config.DefaultEnvPrefix, k) + "=" + v
@@ -37,6 +39,7 @@ func startRudderServer(ctx context.Context, g *errgroup.Group, name, binaryPath
3739
if err := cmd.Start(); err != nil {
3840
return fmt.Errorf("server %q: failed to start: %w", name, err)
3941
}
42+
defer convertCoverageData(t, coverDir, name+"-profile.out")
4043
if err := cmd.Wait(); err != nil {
4144
if exitErr, ok := err.(*exec.ExitError); ok {
4245
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
@@ -50,3 +53,11 @@ func startRudderServer(ctx context.Context, g *errgroup.Group, name, binaryPath
5053
return nil
5154
})
5255
}
56+
57+
func convertCoverageData(t *testing.T, coverDir, outputFile string) {
58+
cmd := exec.Command("go", "tool", "covdata", "textfmt", "-i="+coverDir, "-o="+outputFile)
59+
cmd.Stderr = os.Stderr
60+
if err := cmd.Run(); err != nil {
61+
t.Logf("failed to convert coverage data: %v", err)
62+
}
63+
}

0 commit comments

Comments
 (0)