Skip to content

Commit

Permalink
benchmark-json: fix a bug that invalid JSON may be generated
Browse files Browse the repository at this point in the history
It's happen when multiple tests generate benchmarks.
  • Loading branch information
kou committed Feb 5, 2024
1 parent c1c98a4 commit 1afc81c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/grntest/reporters/benchmark-json-reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
module Grntest
module Reporters
class BenchmarkJSONReporter < BaseReporter
def initialize(tester)
super
end

def on_start(result)
puts(<<-JSON)
{
Expand All @@ -40,11 +36,12 @@ def on_start(result)
"mhz_per_cpu": #{cpu_cycles_per_second / 1_000_000.0},
JSON
end
puts(<<-JSON)
print(<<-JSON.chomp)
"caches": []
},
"benchmarks": [
JSON
@first_benchmark = true
end

def on_worker_start(worker)
Expand Down Expand Up @@ -79,6 +76,8 @@ def on_test_no_check(worker, result)

def on_test_finish(worker, result)
return if result.benchmarks.empty?
print(",") unless @first_benchmark
puts
benchmarks = result.benchmarks.collect do |benchmark|
name = "#{worker.suite_name}/#{result.test_name}"
<<-JSON.chomp
Expand All @@ -94,7 +93,8 @@ def on_test_finish(worker, result)
}
JSON
end
puts(benchmarks.join(",\n"))
print(benchmarks.join(",\n"))
@first_benchmark = false
end

def on_suite_finish(worker)
Expand All @@ -104,6 +104,7 @@ def on_worker_finish(worker)
end

def on_finish(result)
puts
puts(<<-JSON)
]
}
Expand Down

0 comments on commit 1afc81c

Please sign in to comment.