specwrk 0.12.0 → 0.13.1

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: d642db71c542c4b2dbf17038db546a34f713ffccb010dc903e4e7a96c8071016
4
- data.tar.gz: 00fd8258a2441acd31c4a484c2e039ad5e83028e8c10eef509cdca070daab1c8
3
+ metadata.gz: b3028afb58991e7fc5837333b22d842ba261c6fa5985809db231b21fb40fa904
4
+ data.tar.gz: b3471eafa04b678db1b14cf0684296677dbe995fb2f3a5f920659479110e291f
5
5
  SHA512:
6
- metadata.gz: 6c88c00baa4d0455e8b928e276e6c66cf66fd881f7e9193a4e19f665a93d7b177b18e5f2cd00a8605ef4613e9607634791527898836f85f99bec0d3faf17e3d7
7
- data.tar.gz: 7370d6c27e8b052a17bcc93d84fdbea18efab35792ec6f010cc21d05a45ed8aad4cc29e1c24e4b5e10aca65787f8fb08bc7bf94fa4e928293e41405a300259d6
6
+ metadata.gz: 5ed970474e4a193778c33c113f374ffe8146dca152fb14e991f4a2b1970d1b71fee7050b78029ecd7fd3594b16dbd594d94cacd00e29e98ba7eeefc77c8bed90
7
+ data.tar.gz: 6a22138e628cd93aa6db4ceaf06d04b702d540765c53c41a0cefe04192af218394a0c5df6aec0200c5e3fcaadae8d521d3b9839290422b562819b6c78701b005
@@ -44,12 +44,13 @@ module Specwrk
44
44
  raise Errno::ECONNREFUSED unless connected
45
45
  end
46
46
 
47
- attr_reader :last_request_at, :retry_count
47
+ attr_reader :last_request_at, :retry_count, :worker_status
48
48
 
49
49
  def initialize
50
50
  @mutex = Mutex.new
51
51
  @http = self.class.build_http
52
52
  @http.start
53
+ @worker_status = 1
53
54
  end
54
55
 
55
56
  def close
@@ -99,12 +100,6 @@ module Specwrk
99
100
  end
100
101
  end
101
102
 
102
- def complete_examples(examples)
103
- response = post "/complete", body: examples.to_json
104
-
105
- (response.code == "200") ? true : raise(UnhandledResponseError.new("#{response.code}: #{response.body}"))
106
- end
107
-
108
103
  def complete_and_fetch_examples(examples)
109
104
  response = post "/complete_and_pop", body: examples.to_json
110
105
 
@@ -171,7 +166,11 @@ module Specwrk
171
166
  def make_request(request)
172
167
  @mutex.synchronize do
173
168
  @last_request_at = Time.now
174
- @http.request(request).tap { @retry_count = 0 }
169
+ @http.request(request).tap do |response|
170
+ @retry_count = 0
171
+
172
+ @worker_status = response["x-specwrk-status"].to_i if response["x-specwrk-status"]
173
+ end
175
174
  end
176
175
  end
177
176
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "json"
4
4
  require "base64"
5
+ require "securerandom"
5
6
 
6
7
  require "specwrk/store/base_adapter"
7
8
 
@@ -126,7 +127,7 @@ module Specwrk
126
127
  private
127
128
 
128
129
  def write(filename, content)
129
- tmp_filename = [filename, "tmp"].join(".")
130
+ tmp_filename = [filename, SecureRandom.uuid, "tmp"].join(".")
130
131
 
131
132
  File.binwrite(tmp_filename, content)
132
133
 
data/lib/specwrk/store.rb CHANGED
@@ -72,7 +72,7 @@ module Specwrk
72
72
  end
73
73
 
74
74
  def to_h
75
- adapter.multi_read(*keys).transform_keys!(&:to_sym)
75
+ multi_read(*keys).transform_keys!(&:to_sym)
76
76
  end
77
77
 
78
78
  def inspect
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Specwrk
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.1"
5
5
  end
@@ -88,8 +88,6 @@ module Specwrk
88
88
  Endpoints::Heartbeat
89
89
  when ["POST", "/pop"]
90
90
  Endpoints::Pop
91
- when ["POST", "/complete"]
92
- Endpoints::Complete
93
91
  when ["POST", "/complete_and_pop"]
94
92
  Endpoints::CompleteAndPop
95
93
  when ["POST", "/seed"]
@@ -33,6 +33,8 @@ module Specwrk
33
33
 
34
34
  after_lock
35
35
 
36
+ final_response[1]["x-specwrk-status"] = worker_status.to_s
37
+
36
38
  final_response
37
39
  end
38
40
 
@@ -102,6 +104,12 @@ module Specwrk
102
104
  @worker ||= Store.new(ENV.fetch("SPECWRK_SRV_STORE_URI", "memory:///"), File.join(run_id, "workers", request.get_header("HTTP_X_SPECWRK_ID").to_s))
103
105
  end
104
106
 
107
+ def worker_status
108
+ return 0 if worker[:failed].nil? && completed.any? # worker starts after run has completed
109
+
110
+ worker[:failed] || 1
111
+ end
112
+
105
113
  def run_id
106
114
  request.get_header("HTTP_X_SPECWRK_RUN")
107
115
  end
@@ -190,29 +198,6 @@ module Specwrk
190
198
  end
191
199
  end
192
200
 
193
- class Complete < Base
194
- def with_response
195
- warn "[DEPRECATED] This endpoint will be retired in favor of CompleteAndPop. Upgrade your clients."
196
- completed.merge!(completed_examples)
197
- processing.delete(*completed_examples.keys)
198
-
199
- ok
200
- end
201
-
202
- private
203
-
204
- def completed_examples
205
- @completed_data ||= payload.map { |example| [example[:id], example] if processing[example[:id]] }.compact.to_h
206
- end
207
-
208
- # We don't care about exact values here, just approximate run times are fine
209
- # So if we overwrite run times from another process it is nbd
210
- def after_lock
211
- run_time_data = payload.map { |example| [example[:id], example[:run_time]] }.to_h
212
- run_times.merge! run_time_data
213
- end
214
- end
215
-
216
201
  class Popable < Base
217
202
  private
218
203
 
@@ -261,6 +246,8 @@ module Specwrk
261
246
  end
262
247
 
263
248
  class CompleteAndPop < Popable
249
+ EXAMPLE_STATUSES = %w[passed failed pending]
250
+
264
251
  def with_response
265
252
  completed.merge!(completed_examples)
266
253
  processing.delete(*completed_examples.keys)
@@ -274,10 +261,22 @@ module Specwrk
274
261
  @completed_data ||= payload.map { |example| [example[:id], example] if processing[example[:id]] }.compact.to_h
275
262
  end
276
263
 
277
- # We don't care about exact values here, just approximate run times are fine
278
- # So if we overwrite run times from another process it is nbd
264
+ def completed_examples_status_counts
265
+ @completed_examples_status_counts ||= completed_examples.values.map { |example| example[:status] }.tally
266
+ end
267
+
279
268
  def after_lock
269
+ # We don't care about exact values here, just approximate run times are fine
270
+ # So if we overwrite run times from another process it is nbd
280
271
  run_times.merge! run_time_data
272
+
273
+ # workers are single proces, single-threaded, so safe to do this work without the lock
274
+ existing_status_counts = worker.multi_read(*EXAMPLE_STATUSES)
275
+ new_status_counts = EXAMPLE_STATUSES.map do |status|
276
+ [status, existing_status_counts.fetch(status, 0) + completed_examples_status_counts.fetch(status, 0)]
277
+ end.to_h
278
+
279
+ worker.merge!(new_status_counts)
281
280
  end
282
281
 
283
282
  def run_time_data
@@ -5,19 +5,14 @@ module Specwrk
5
5
  class CompletionFormatter
6
6
  RSpec::Core::Formatters.register self, :stop
7
7
 
8
- attr_reader :examples, :failure
8
+ attr_reader :examples
9
9
 
10
10
  def initialize
11
11
  @examples = []
12
- @failure = false
13
12
  end
14
13
 
15
14
  def stop(group_notification)
16
15
  group_notification.notifications.map do |notification|
17
- unless failure
18
- @failure = notification.example.execution_result.status == :failed
19
- end
20
-
21
16
  examples << {
22
17
  id: notification.example.id,
23
18
  full_description: notification.example.full_description,
@@ -11,12 +11,6 @@ require "specwrk/worker/null_formatter"
11
11
  module Specwrk
12
12
  class Worker
13
13
  class Executor
14
- attr_reader :example_processed
15
-
16
- def failure
17
- completion_formatter.failure
18
- end
19
-
20
14
  def examples
21
15
  completion_formatter.examples
22
16
  end
@@ -29,7 +23,6 @@ module Specwrk
29
23
  reset!
30
24
 
31
25
  example_ids = examples.map { |example| example[:id] }
32
- @example_processed ||= true unless example_ids.size.zero? # only ever toggle from nil => true
33
26
 
34
27
  options = RSpec::Core::ConfigurationOptions.new rspec_options + example_ids
35
28
  RSpec::Core::Runner.new(options).run($stderr, $stdout)
@@ -110,11 +110,10 @@ module Specwrk
110
110
  attr_reader :running, :client, :executor
111
111
 
112
112
  def status
113
- return 1 if !executor.example_processed && !@all_examples_completed
114
- return 1 if executor.failure
113
+ return 0 if @all_examples_completed && client.worker_status.zero?
115
114
  return 1 if Specwrk.force_quit
116
115
 
117
- 0
116
+ client.worker_status
118
117
  end
119
118
 
120
119
  def warn(msg)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specwrk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Westendorf