Merge pull request #91 from entireio/fix/bench-exit-code-and-sentinels · Entire
Merge pull request #91 from entireio/fix/bench-exit-code-and-sentinels
a7d5565→main·Soph·4w ago·2 files·+43 added/-2 removed
Changes
2
cmd/git-sync-bench
Mmain.go+18/-2
Mmain_test.go+25
228 unmodified lines
229
230
231
232
232
233
234
235
235
236
237
238
239
240
241
242
243
119 unmodified lines
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
228 unmodified lines
return fmt.Errorf("marshal report: %w", err)
}
fmt.Println(string(data))
return nil
} else {
printTextReport(report)
}
printTextReport(report)
// Report (printed above) is the useful artifact; still exit non-zero so a
// failed run can't pass as success in CI.
if report.Aggregate.FailedRuns > 0 {
return fmt.Errorf("%d of %d benchmark run(s) failed", report.Aggregate.FailedRuns, len(report.Runs))
}
return nil
}
119 unmodified lines
summary.AvgBatchCount = float64(totalBatchCount) / float64(batchedRuns)
summary.AvgPlannedBatchCount = float64(totalPlanned) / float64(batchedRuns)
}
// The Min* fields start at -1 as an "unset" sentinel updated by the first
// qualifying run. With no such run, replace the sentinel with 0 so it never
// leaks into the report (the batch counts are omitempty, so 0 drops them).
if okRuns == 0 {
summary.MinWallMillis = 0
summary.MinSyncElapsedMillis = 0
}
if batchedRuns == 0 {
summary.MinBatchCount = 0
summary.MinPlannedBatchCount = 0
}
summary.RelayModes = uniqueStrings(relayModes)
return summary
}
Mcmd/git-sync-bench/main.go+18/-2
1
2
3
4
5
6
7
8
69 unmodified lines
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"bytes"
"encoding/json"
"testing"
"entire.io/entire/git-sync/unstable"
69 unmodified lines
}
// When every run fails there are no measurements, so the "unset" -1 sentinels
// must be cleared rather than leaking into the (JSON) report.
func TestSummarizeRunsAllFailedHasNoSentinels(t *testing.T) {
runs := []runSummary{{Index: 1, Error: "boom"}, {Index: 2, Error: "kaboom"}}
got := summarizeRuns(runs)
if got.SuccessfulRuns != 0 || got.FailedRuns != 2 {
t.Fatalf("unexpected counts: %+v", got)
}
if got.MinWallMillis != 0 || got.MinSyncElapsedMillis != 0 ||
got.MinBatchCount != 0 || got.MinPlannedBatchCount != 0 {
t.Fatalf("expected sentinels cleared to 0, got %+v", got)
}
data, err := json.Marshal(got)
if err != nil {
t.Fatalf("marshal: %v", err)
}
if bytes.Contains(data, []byte("-1")) {
t.Fatalf("the -1 sentinel leaked into JSON: %s", data)
}
}
func TestNormalizeRepoURL(t *testing.T) {
got, err := normalizeRepoURL("https://example.com/repo.git")
if err != nil {
// handle error
}
}