ruby_ci 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2920f9bf7f47278319623491a637407d94b46160479c83d0f94d96d1652ba139
4
- data.tar.gz: 9ae3ab078220371e34526bd53d47e2e57aba01fc39fd49709b00fdb43737027b
3
+ metadata.gz: aa6e2fa74cc6d0e4b24da9318e739db4491b91195a20aaab6e777470934d2819
4
+ data.tar.gz: 5228af6801441a991d0f6802fb8ea28c658512f66240d1b1b2530337dcc8577d
5
5
  SHA512:
6
- metadata.gz: eff0af87982d50bec4da005de4179b9cdebfc18cc0b8b2bba776d328f37a6c499695f80e9bb73afd2c3a67742b4f12356f037f1d7f9d1ded8e8021f0bb29d444
7
- data.tar.gz: 308527f4679a5489a7ab5b3c387f841869f128ab3e93c438faf78477233e53b08ad2803445d617bf81ad167e2f9103b996014b9bed29c56a3fda6550e7981901
6
+ metadata.gz: d03cdba5e3d219f235036e30ce595932eb69da946b1cb2c2639db9fd56abb8f883261515519cd4eec3559ba6964b8fb63964b270cef2a531a90bae684986fabd
7
+ data.tar.gz: 639d761bf5da50ec7a35950e500682501dcca9c92017fed76631344f9436df42501ea8aecfe85814010abb24a194aa56f4a7ef4192c1c08df7771bfd3ddf616d
@@ -10,7 +10,7 @@ module RubyCI
10
10
  end
11
11
 
12
12
  def exit_code(examples_passed=false)
13
- run_time = Time.now - (@rspec_started_at || 1.second.ago)
13
+ run_time = Time.now - (@rspec_started_at || 1.seconds.ago)
14
14
  events = @world.non_example_failure ? [['RSPEC_DRYRUN', { failed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"], data: 'error' }]] : [['RSPEC_DRYRUN', { succeed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]]
15
15
  STDOUT.puts events.inspect
16
16
  json_events = {
@@ -0,0 +1,241 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyCI
4
+ class RspecRunFormatter
5
+ RSpec::Core::Formatters.register self,
6
+ :start,
7
+ :example_group_started,
8
+ :example_started,
9
+ :example_passed,
10
+ :example_failed,
11
+ :example_pending,
12
+ :example_group_finished,
13
+ :close
14
+
15
+ def initialize(output)
16
+ @output = output
17
+ @event_output = {}
18
+ @is_failed = false
19
+ @current_path = []
20
+ @current_path_started_at = []
21
+ @max_heap_live_num = 0
22
+ @dup_stdout = STDOUT.clone
23
+ @events = []
24
+
25
+ $stdout = StringIO.new()
26
+
27
+ @log_thread = Thread.new do
28
+ loop do
29
+ sleep 10
30
+ check_heap_live_num
31
+ @should_send_events = true
32
+ end
33
+ end
34
+ end
35
+
36
+ def time_now
37
+ time_frozen? ? Timecop.return { Time.now } : Time.now
38
+ end
39
+
40
+ def time_frozen?
41
+ return unless defined?(Timecop)
42
+ Timecop.frozen?
43
+ end
44
+
45
+ def rspec_runner_index
46
+ ENV["TEST_ENV_NUMBER"]
47
+ end
48
+
49
+ def send_events
50
+ @should_send_events = false
51
+
52
+ if @events.length > 0
53
+ json_events = {
54
+ build_id: RubyCI.configuration.orig_build_id,
55
+ compressed_data: Base64.strict_encode64(Zlib::Deflate.deflate(JSON.fast_generate(@events), 9)),
56
+ }
57
+
58
+ RubyCI.send_events(json_events)
59
+
60
+ @events = []
61
+ end
62
+ end
63
+
64
+ def check_heap_live_num
65
+ @max_heap_live_num = [@max_heap_live_num, GC.stat[:heap_live_slots] || GC.stat[:heap_live_num]].max
66
+ end
67
+
68
+ def passed?
69
+ !@is_failed
70
+ end
71
+
72
+ def start(start_notification)
73
+ # $stderr = $stdout
74
+
75
+ data = {
76
+ load_time: start_notification.load_time,
77
+ example_count: start_notification.count,
78
+ started_at: time_now.to_s
79
+ }
80
+
81
+ return if running_only_failed? ||
82
+ running_gem_or_engine? ||
83
+ ENV["EXTRA_SLOWER_RUN"]
84
+
85
+ msg(:start, data)
86
+ end
87
+
88
+ def close(null_notification)
89
+ # check_heap_live_num
90
+ msg(:gc_stat, GC.stat.merge(max_heap_live_num: @max_heap_live_num))
91
+ unless running_only_failed? || ENV["EXTRA_SLOWER_RUN"] || running_gem_or_engine?
92
+ msg(:close, {final_output: get_output})
93
+ end
94
+ send_events
95
+ $stdout = @dup_stdout
96
+ end
97
+
98
+ def example_group_started(group_notification)
99
+ metadata = group_notification.group.metadata
100
+ @current_path_started_at << time_now
101
+
102
+ if @current_path.size == 0
103
+ @example_failed_index = 0
104
+ file_path = metadata[:file_path].gsub("./".freeze, "".freeze)
105
+ file_path = [ENV["DIR_PREFIX"], file_path].join("/") if ENV["DIR_PREFIX"]
106
+ @current_path << file_path
107
+ end
108
+
109
+ @current_path << id(metadata)
110
+
111
+ msg(:group_started, [
112
+ path_with_file(group_notification.group),
113
+ {
114
+ line_number: metadata[:line_number],
115
+ description: metadata[:description],
116
+ }
117
+ ])
118
+ end
119
+
120
+ def example_started(example_notification)
121
+ @output_before = get_output
122
+ end
123
+
124
+ def example_passed(example_notification)
125
+ metadata = example_notification.example.metadata
126
+ broadcast_example_finished(serialize_example(metadata, "passed".freeze), example_notification.example)
127
+ end
128
+
129
+ def example_failed(example_notification)
130
+ @example_failed_index += 1
131
+ metadata = example_notification.example.metadata
132
+ fully_formatted = example_notification.fully_formatted(@example_failed_index, ::RSpec::Core::Formatters::ConsoleCodes)
133
+
134
+ broadcast_example_finished(
135
+ serialize_example(metadata, "failed".freeze, fully_formatted),
136
+ example_notification.example
137
+ )
138
+ end
139
+
140
+ def example_pending(example_notification)
141
+ metadata = example_notification.example.metadata
142
+ broadcast_example_finished(
143
+ serialize_example(metadata, "pending".freeze),
144
+ example_notification.example
145
+ )
146
+ end
147
+
148
+ def example_group_finished(group_notification)
149
+ run_time = time_now - @current_path_started_at.pop
150
+ if (run_time < 0) || (run_time > 2400)
151
+ run_time = 0.525
152
+ end
153
+ msg(:group_finished, [path_with_file(group_notification.group), {run_time: run_time}])
154
+ # msg(:group_finished, [@current_path.map(&:to_s), {run_time: run_time}])
155
+ @current_path.pop
156
+ @current_path.pop if @current_path.size == 1 # Remove the file_path at the beggining
157
+ end
158
+
159
+ def path_with_file(group)
160
+ file_path = group.parent_groups.last.file_path.gsub("./".freeze, "".freeze)
161
+
162
+ group.metadata[:scoped_id].split(":").unshift(file_path)
163
+ end
164
+
165
+ private
166
+
167
+ def running_gem_or_engine?
168
+ !!ENV["DIR_PREFIX"]
169
+ end
170
+
171
+ def running_only_failed?
172
+ !!ENV["RERUN_FAILED_FILES"]
173
+ end
174
+
175
+ def serialize_example(metadata, status, fully_formatted = nil)
176
+ run_time = metadata[:execution_result].run_time
177
+ if (run_time < 0) || (run_time > 2400)
178
+ run_time = 0.525
179
+ end
180
+
181
+ result = {
182
+ id: id(metadata),
183
+ status: status,
184
+ line_number: metadata[:line_number].to_s,
185
+ description: metadata[:description],
186
+ run_time: run_time,
187
+ fully_formatted: fully_formatted,
188
+ scoped_id: metadata[:scoped_id],
189
+ }.compact
190
+
191
+ result[:gem_or_engine] = true if running_gem_or_engine?
192
+
193
+ if running_only_failed?
194
+ result[:reruned] = true
195
+ elsif status == "failed" && !running_gem_or_engine?
196
+ File.write('tmp/rspec_failures', "#{@current_path.first}[#{metadata[:scoped_id]}]", mode: 'a+')
197
+ end
198
+
199
+ if status == "failed"
200
+ img_path = metadata.dig(:screenshot, :image) ||
201
+ fully_formatted&.scan(/\[Screenshot Image\]: (.*)$/).flatten.first&.strip&.chomp ||
202
+ fully_formatted&.scan(/\[Screenshot\]: (.*)$/).flatten.first&.strip&.chomp
203
+
204
+ if img_path && File.exist?(img_path)
205
+ STDOUT.puts "SCREENSHOT!"
206
+ result[:screenshots_base64] ||= []
207
+ result[:screenshots_base64] << Base64.strict_encode64(File.read(img_path))
208
+ end
209
+ end
210
+ @last_example_finished_at = time_now
211
+ # TODO annalyze this: run_time: metadata[:execution_result].run_time,
212
+ result
213
+ end
214
+
215
+ def msg(event, data)
216
+ @events << ["rspec_#{event}".upcase, [rspec_runner_index, data]]
217
+ end
218
+
219
+ def id(metadata)
220
+ metadata[:scoped_id].split(":").last || raise("No scoped id")
221
+ end
222
+
223
+ def broadcast_example_finished(data, example)
224
+ msg(:example_finished, [
225
+ path_with_file(example.example_group),
226
+ data.merge(output_inside: get_output, output_before: @output_before)
227
+ ])
228
+
229
+ send_events if @should_send_events
230
+ end
231
+
232
+ def get_output
233
+ return if $stdout.pos == 0
234
+ $stdout.rewind
235
+ res = $stdout.read
236
+ $stdout.flush
237
+ $stdout.rewind
238
+ res
239
+ end
240
+ end
241
+ end
@@ -88,7 +88,7 @@ module RubyCI
88
88
  end
89
89
 
90
90
  def exit_code(examples_passed=false)
91
- run_time = Time.now - (@rspec_started_at || 1.second.ago)
91
+ run_time = Time.now - (@rspec_started_at || 1.seconds.ago)
92
92
  events = @world.non_example_failure ? [['RSPEC_RUN', { failed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]] : [['RSPEC_RUN', { succeed_after: run_time, test_env_number: ENV["TEST_ENV_NUMBER"] }]]
93
93
  json_events = {
94
94
  build_id: RubyCI.configuration.orig_build_id,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCI
4
- VERSION = "0.2.9"
4
+ VERSION = "0.2.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ale ∴
@@ -128,6 +128,7 @@ files:
128
128
  - lib/ruby_ci/extract_definitions.rb
129
129
  - lib/ruby_ci/rspec_dryrun_formatter.rb
130
130
  - lib/ruby_ci/rspec_formatter.rb
131
+ - lib/ruby_ci/rspec_run_formatter.rb
131
132
  - lib/ruby_ci/ruby_critic/cli/application.rb
132
133
  - lib/ruby_ci/runner_prepend.rb
133
134
  - lib/ruby_ci/simple_cov.rb