Skip to content

Commit fe9db3c

Browse files
authored
Merge pull request #8 from smileart/fix/loading_time_summary
Fix: Loading time summary not being reflected in the report
2 parents 2fa9129 + af6e0be commit fe9db3c

File tree

7 files changed

+93
-6
lines changed

7 files changed

+93
-6
lines changed

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,60 @@
99

1010
# rspec failure tracking
1111
.rspec_status
12+
13+
14+
# Created by https://www.toptal.com/developers/gitignore/api/macos,vim
15+
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,vim
16+
17+
### macOS ###
18+
# General
19+
.DS_Store
20+
.AppleDouble
21+
.LSOverride
22+
23+
# Icon must end with two \r
24+
Icon
25+
26+
27+
# Thumbnails
28+
._*
29+
30+
# Files that might appear in the root of a volume
31+
.DocumentRevisions-V100
32+
.fseventsd
33+
.Spotlight-V100
34+
.TemporaryItems
35+
.Trashes
36+
.VolumeIcon.icns
37+
.com.apple.timemachine.donotpresent
38+
39+
# Directories potentially created on remote AFP share
40+
.AppleDB
41+
.AppleDesktop
42+
Network Trash Folder
43+
Temporary Items
44+
.apdisk
45+
46+
### Vim ###
47+
# Swap
48+
[._]*.s[a-v][a-z]
49+
!*.svg # comment out if you don't need vector files
50+
[._]*.sw[a-p]
51+
[._]s[a-rt-v][a-z]
52+
[._]ss[a-gi-z]
53+
[._]sw[a-p]
54+
55+
# Session
56+
Session.vim
57+
Sessionx.vim
58+
59+
# Temporary
60+
.netrwhist
61+
*~
62+
# Auto-generated tag files
63+
tags
64+
# Persistent undo
65+
[._]*.un~
66+
67+
# End of https://www.toptal.com/developers/gitignore/api/macos,vim
68+

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
turbo_tests (1.2.1)
4+
turbo_tests (1.2.2)
55
bundler
66
parallel_tests (~> 3.3)
77
rspec (~> 3.10.0)

lib/turbo_tests/json_rows_formatter.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module TurboTests
2222
class JsonRowsFormatter
2323
RSpec::Core::Formatters.register(
2424
self,
25+
:start,
2526
:close,
2627
:example_failed,
2728
:example_passed,
@@ -38,6 +39,14 @@ def initialize(output)
3839
@output = output
3940
end
4041

42+
43+
def start(notification)
44+
output_row(
45+
"type" => :load_summary,
46+
"summary" => load_summary_to_json(notification)
47+
)
48+
end
49+
4150
def example_group_started(notification)
4251
output_row(
4352
"type" => :group_started,
@@ -48,7 +57,7 @@ def example_group_started(notification)
4857
def example_group_finished(notification)
4958
output_row(
5059
"type" => :group_finished,
51-
"example" => group_to_json(notification)
60+
"group" => group_to_json(notification)
5261
)
5362
end
5463

@@ -130,6 +139,13 @@ def example_to_json(example)
130139
}
131140
end
132141

142+
def load_summary_to_json(notification)
143+
{
144+
count: notification.count,
145+
load_time: notification.load_time
146+
}
147+
end
148+
133149
def group_to_json(notification)
134150
{
135151
"group": {

lib/turbo_tests/reporter.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module TurboTests
44
class Reporter
5+
attr_writer :load_time
6+
57
def self.from_config(formatter_config, start_time)
68
reporter = new(start_time)
79

@@ -27,6 +29,7 @@ def initialize(start_time)
2729
@failed_examples = []
2830
@all_examples = []
2931
@start_time = start_time
32+
@load_time = 0
3033
end
3134

3235
def add(name, outputs)
@@ -93,7 +96,7 @@ def finish
9396
@all_examples,
9497
@failed_examples,
9598
@pending_examples,
96-
0,
99+
@load_time,
97100
0
98101
))
99102
delegate_to_formatters(:close,

lib/turbo_tests/runner.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def initialize(opts)
3939
@verbose = opts[:verbose]
4040
@fail_fast = opts[:fail_fast]
4141
@count = opts[:count]
42+
@load_time = 0
43+
@load_count = 0
4244

4345
@failure_count = 0
4446
@runtime_log = "tmp/parallel_runtime_rspec.log"
@@ -170,6 +172,11 @@ def handle_messages
170172
when "example_pending"
171173
example = FakeExample.from_obj(message["example"])
172174
@reporter.example_pending(example)
175+
when "load_summary"
176+
message = message["summary"]
177+
# NOTE: notifications order and content is not guaranteed hence the fetch
178+
# and count increment tracking to get the latest accumulated load time
179+
@reporter.load_time = message["load_time"] if message.fetch("count", 0) > @load_count
173180
when "example_failed"
174181
example = FakeExample.from_obj(message["example"])
175182
@reporter.example_failed(example)
@@ -203,7 +210,7 @@ def report_number_of_tests(groups)
203210

204211
num_processes = groups.size
205212
num_tests = groups.map(&:size).sum
206-
tests_per_process = (num_processes == 0 ? 0 : num_tests / num_processes)
213+
tests_per_process = (num_processes == 0 ? 0 : num_tests.to_f / num_processes).round
207214

208215
puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process"
209216
end

lib/turbo_tests/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module TurboTests
2-
VERSION = "1.2.1"
2+
VERSION = "1.2.2"
33
end

spec/doc_formatter_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This delay visualizes the effect of load time calculation.
2+
# https://github.com/serpapi/turbo_tests/pull/8#issue-583037321
3+
sleep 3
4+
15
RSpec.describe "Top-level context" do
26
describe "#instance_method" do
37
it "does what it's supposed to" do
@@ -8,4 +12,4 @@
812
expect(false).not_to be_truthy
913
end
1014
end
11-
end
15+
end

0 commit comments

Comments
 (0)