Skip to content

Commit

Permalink
Merge pull request #715 from loadimpact/json-collector-fix
Browse files Browse the repository at this point in the history
Prevent the JSON collector from closing stdout
  • Loading branch information
na-- authored Jul 17, 2018
2 parents 7796615 + 82fd9af commit f4875fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion release notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Description of feature.
## Bugs fixed!

* Logging: using the `--no-color` flag caused k6 to print output intended for `sdtout` to `stderr` instead. (#712)
* Logging: some error messages originating from Go's standard library did not obey the `--logformat` option. (#712)
* Logging: some error messages originating from Go's standard library did not obey the `--logformat` option. (#712)
* JSON output: when the standard output was used, the JSON collector closed it before k6 was finished printing the end-of-test summary to it (#715)
9 changes: 8 additions & 1 deletion stats/json/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ type Collector struct {
// Verify that Collector implements lib.Collector
var _ lib.Collector = &Collector{}

// Similar to ioutil.NopCloser, but for writers
type nopCloser struct {
io.Writer
}

func (nopCloser) Close() error { return nil }

func (c *Collector) HasSeenMetric(str string) bool {
for _, n := range c.seenMetrics {
if n == str {
Expand All @@ -53,7 +60,7 @@ func (c *Collector) HasSeenMetric(str string) bool {
func New(fs afero.Fs, fname string) (*Collector, error) {
if fname == "" || fname == "-" {
return &Collector{
outfile: os.Stdout,
outfile: nopCloser{os.Stdout},
fname: "-",
}, nil
}
Expand Down

0 comments on commit f4875fb

Please sign in to comment.