Skip to content

fix(scaletest): output error and trace instead of {} for json output #10075

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

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
deterministic output
  • Loading branch information
mafredri committed Oct 5, 2023
commit bc6278c6c532e11db6c6c18edb7f95babef6490a
7 changes: 6 additions & 1 deletion scaletest/harness/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"encoding/json"
"fmt"
"io"
"sort"
"strings"
"time"

"github.com/coder/coder/v2/coderd/httpapi"
"golang.org/x/exp/maps"
)

// Results is the full compiled results for a set of test runs.
Expand Down Expand Up @@ -101,7 +103,10 @@ func (h *TestHarness) Results() Results {
// PrintText prints the results as human-readable text to the given writer.
func (r *Results) PrintText(w io.Writer) {
var totalDuration time.Duration
for _, run := range r.Runs {
keys := maps.Keys(r.Runs)
sort.Strings(keys)
for _, key := range keys {
run := r.Runs[key]
totalDuration += time.Duration(run.Duration)
if run.Error == nil {
continue
Expand Down
10 changes: 8 additions & 2 deletions scaletest/harness/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package harness_test
import (
"bytes"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -106,7 +109,7 @@ Test results:
"started_at": "2023-10-05T12:03:56.395813665Z",
"duration": "1s",
"duration_ms": 1000,
"error": "test-0/0 error:\n github.com/coder/coder/v2/scaletest/harness_test.Test_Results\n /home/coder/src/coder/coder/scaletest/harness/results_test.go:40"
"error": "test-0/0 error:\n github.com/coder/coder/v2/scaletest/harness_test.Test_Results\n [working_directory]results_test.go:43"
},
"test-0/1": {
"full_id": "test-0/1",
Expand All @@ -131,6 +134,9 @@ Test results:
}
}
`
wd, err := os.Getwd()
require.NoError(t, err)
wantJSON = strings.Replace(wantJSON, "[working_directory]", wd+string(filepath.Separator), 1)

out := bytes.NewBuffer(nil)
results.PrintText(out)
Expand All @@ -140,7 +146,7 @@ Test results:
out.Reset()
enc := json.NewEncoder(out)
enc.SetIndent("", "\t")
err := enc.Encode(results)
err = enc.Encode(results)
require.NoError(t, err)

assert.Empty(t, cmp.Diff(wantJSON, out.String()), "JSON result does not match (-want +got)")
Expand Down