Skip to content

Commit

Permalink
Merge pull request #8 from smileart/fix/loading_time_summary
Browse files Browse the repository at this point in the history
Fix: Loading time summary not being reflected in the report
  • Loading branch information
ilyazub authored Mar 2, 2021
2 parents 2fa9129 + af6e0be commit fe9db3c
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,60 @@

# rspec failure tracking
.rspec_status


# Created by https://www.toptal.com/developers/gitignore/api/macos,vim
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,vim

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# End of https://www.toptal.com/developers/gitignore/api/macos,vim

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
turbo_tests (1.2.1)
turbo_tests (1.2.2)
bundler
parallel_tests (~> 3.3)
rspec (~> 3.10.0)
Expand Down
18 changes: 17 additions & 1 deletion lib/turbo_tests/json_rows_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module TurboTests
class JsonRowsFormatter
RSpec::Core::Formatters.register(
self,
:start,
:close,
:example_failed,
:example_passed,
Expand All @@ -38,6 +39,14 @@ def initialize(output)
@output = output
end


def start(notification)
output_row(
"type" => :load_summary,
"summary" => load_summary_to_json(notification)
)
end

def example_group_started(notification)
output_row(
"type" => :group_started,
Expand All @@ -48,7 +57,7 @@ def example_group_started(notification)
def example_group_finished(notification)
output_row(
"type" => :group_finished,
"example" => group_to_json(notification)
"group" => group_to_json(notification)
)
end

Expand Down Expand Up @@ -130,6 +139,13 @@ def example_to_json(example)
}
end

def load_summary_to_json(notification)
{
count: notification.count,
load_time: notification.load_time
}
end

def group_to_json(notification)
{
"group": {
Expand Down
5 changes: 4 additions & 1 deletion lib/turbo_tests/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module TurboTests
class Reporter
attr_writer :load_time

def self.from_config(formatter_config, start_time)
reporter = new(start_time)

Expand All @@ -27,6 +29,7 @@ def initialize(start_time)
@failed_examples = []
@all_examples = []
@start_time = start_time
@load_time = 0
end

def add(name, outputs)
Expand Down Expand Up @@ -93,7 +96,7 @@ def finish
@all_examples,
@failed_examples,
@pending_examples,
0,
@load_time,
0
))
delegate_to_formatters(:close,
Expand Down
9 changes: 8 additions & 1 deletion lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def initialize(opts)
@verbose = opts[:verbose]
@fail_fast = opts[:fail_fast]
@count = opts[:count]
@load_time = 0
@load_count = 0

@failure_count = 0
@runtime_log = "tmp/parallel_runtime_rspec.log"
Expand Down Expand Up @@ -170,6 +172,11 @@ def handle_messages
when "example_pending"
example = FakeExample.from_obj(message["example"])
@reporter.example_pending(example)
when "load_summary"
message = message["summary"]
# NOTE: notifications order and content is not guaranteed hence the fetch
# and count increment tracking to get the latest accumulated load time
@reporter.load_time = message["load_time"] if message.fetch("count", 0) > @load_count
when "example_failed"
example = FakeExample.from_obj(message["example"])
@reporter.example_failed(example)
Expand Down Expand Up @@ -203,7 +210,7 @@ def report_number_of_tests(groups)

num_processes = groups.size
num_tests = groups.map(&:size).sum
tests_per_process = (num_processes == 0 ? 0 : num_tests / num_processes)
tests_per_process = (num_processes == 0 ? 0 : num_tests.to_f / num_processes).round

puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/turbo_tests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TurboTests
VERSION = "1.2.1"
VERSION = "1.2.2"
end
6 changes: 5 additions & 1 deletion spec/doc_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This delay visualizes the effect of load time calculation.
# https://github.com/serpapi/turbo_tests/pull/8#issue-583037321
sleep 3

RSpec.describe "Top-level context" do
describe "#instance_method" do
it "does what it's supposed to" do
Expand All @@ -8,4 +12,4 @@
expect(false).not_to be_truthy
end
end
end
end

0 comments on commit fe9db3c

Please sign in to comment.