Skip to content

Commit

Permalink
refactor(ui): bring back SummaryData, minor cleanup
Browse files Browse the repository at this point in the history
As per [1], it would be preferable to keep this struct. Though I renamed
some fields and removed the dependency on the entire lib.Options, since
it only requires one value.

This also renames Summary.Write to Summary.SummarizeMetrics, as it's a
more accurate description of what happens, despite of the
"Summary.Summarize" stutter.

[1]: #1143 (comment)
  • Loading branch information
Ivan Mirić committed Oct 15, 2019
1 parent f25e729 commit dd29bd3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
9 changes: 7 additions & 2 deletions cmd/run.go
Expand Up @@ -451,8 +451,13 @@ a commandline interface for interacting with it.`,
}

fprintf(stdout, "\n")
s.Write(stdout, "", engine.Executor.GetRunner().GetDefaultGroup(),
engine.Executor.GetTime(), conf.SummaryTimeUnit.String, engine.Metrics)
s.SummarizeMetrics(stdout, "", ui.SummaryData{
Metrics: engine.Metrics,
RootGroup: engine.Executor.GetRunner().GetDefaultGroup(),
Time: engine.Executor.GetTime(),
TimeUnit: conf.Options.SummaryTimeUnit.String,
})

fprintf(stdout, "\n")
}

Expand Down
19 changes: 13 additions & 6 deletions ui/summary.go
Expand Up @@ -370,11 +370,18 @@ func (s *Summary) summarizeMetrics(w io.Writer, indent string, t time.Duration,
}
}

// Write writes the metrics summary to w
func (s *Summary) Write(w io.Writer, indent string, group *lib.Group,
t time.Duration, timeUnit string, metrics map[string]*stats.Metric) {
if group != nil {
summarizeGroup(w, indent+" ", group)
// SummaryData represents data passed to Summary.SummarizeMetrics
type SummaryData struct {
Metrics map[string]*stats.Metric
RootGroup *lib.Group
Time time.Duration
TimeUnit string
}

// SummarizeMetrics creates a summary of provided metrics and writes it to w.
func (s *Summary) SummarizeMetrics(w io.Writer, indent string, data SummaryData) {
if data.RootGroup != nil {
summarizeGroup(w, indent+" ", data.RootGroup)
}
s.summarizeMetrics(w, indent+" ", t, timeUnit, metrics)
s.summarizeMetrics(w, indent+" ", data.Time, data.TimeUnit, data.Metrics)
}
10 changes: 8 additions & 2 deletions ui/summary_test.go
Expand Up @@ -57,7 +57,7 @@ func TestSummary(t *testing.T) {
}
})

t.Run("Write", func(t *testing.T) {
t.Run("SummarizeMetrics", func(t *testing.T) {
var (
checksOut = " ✓ checks......: 100.00% ✓ 3 ✗ 0 \n"
countOut = " ✗ http_reqs...: 3 3/s\n"
Expand All @@ -80,7 +80,13 @@ func TestSummary(t *testing.T) {
t.Run(fmt.Sprintf("%v", tc.stats), func(t *testing.T) {
var w bytes.Buffer
s, _ := NewSummary(tc.stats)
s.Write(&w, " ", nil, time.Second, "", metrics)

s.SummarizeMetrics(&w, " ", SummaryData{
Metrics: metrics,
RootGroup: nil,
Time: time.Second,
TimeUnit: "",
})
assert.Equal(t, tc.expected, w.String())
})
}
Expand Down

0 comments on commit dd29bd3

Please sign in to comment.