rspec-buildkite-analytics 0.8.0 → 0.8.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: a29588419eb727d74849c54b0d38f5b90974c3f58f083e48958a17288a1dc1fe
4
- data.tar.gz: 1fd5fd323f7737c247b61bcd87ea9778e3f020601514eb52777c0ba5871c24aa
3
+ metadata.gz: 4ac283b3f333632c2909b0dd7b35dd1c4f9765d659489c00d8ae93a169433aa8
4
+ data.tar.gz: eb45c11b5da7a61597b915749f04bb77d46408b764f22cb84dba349ae3fba4f8
5
5
  SHA512:
6
- metadata.gz: 45624d6a321c8ff16008e259b4a3eb3f118449d36947f1cb0efb86c7e988ee3e904a2665be517b4be2cd8075d4c1352d8356df88ac43c615664ec28383ced50f
7
- data.tar.gz: fdb57102cd80974a01e939e8ab8bc8ae3ce22f39ff5a6862cc7cdc9d5250672a93ff966dfa391e47e80cdfaf70354082f0afd9ca1f6d4e1104edb53dbc11d977
6
+ metadata.gz: deb2c39374b9a86cea6ab81b8f81137eb919e78f7d5a5f4ad28fb1cb51dfdbda72f930e71dca67dcd4353860519109627852f52c07238523bc6aeb3b8b83513a
7
+ data.tar.gz: 64036687b205256d27f656066bdc182b936dcb29daa10f6149ce18972303b4b8140c44ab6db22028cce0a19fd84bab4b59d679f4e8f1471f87f86e0c31fe3a1f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.8.1
4
+
5
+ - Improve the EOT confirmation #93 — @blaknite
6
+
3
7
  ## v0.8.0
4
8
 
5
9
  - Support multiple CI platforms and generic env #80 — @blaknite
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-buildkite-analytics (0.8.0)
4
+ rspec-buildkite-analytics (0.8.1)
5
5
  activesupport (>= 5.2, < 8)
6
6
  rspec-core (~> 3.10)
7
7
  rspec-expectations (~> 3.10)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.0.2.3)
13
+ activesupport (7.0.2.4)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
@@ -5,9 +5,9 @@ require_relative "socket_connection"
5
5
  module RSpec::Buildkite::Analytics
6
6
  class Session
7
7
  # Picked 75 as the magic timeout number as it's longer than the TCP timeout of 60s 🤷‍♀️
8
- CONFIRMATION_TIMEOUT = 75
9
- MAX_RECONNECTION_ATTEMPTS = 3
10
- WAIT_BETWEEN_RECONNECTIONS = 5
8
+ CONFIRMATION_TIMEOUT = ENV.fetch("BUILDKITE_ANALYTICS_CONFIRMATION_TIMEOUT") { 75 }.to_i
9
+ MAX_RECONNECTION_ATTEMPTS = ENV.fetch("BUILDKITE_ANALYTICS_RECONNECTION_ATTEMPTS") { 3 }.to_i
10
+ WAIT_BETWEEN_RECONNECTIONS = ENV.fetch("BUILDKITE_ANALYTICS_RECONNECTION_WAIT") { 5 }.to_i
11
11
 
12
12
  class RejectedSubscription < StandardError; end
13
13
  class InitialConnectionFailure < StandardError; end
@@ -116,20 +116,24 @@ module RSpec::Buildkite::Analytics
116
116
  # to which the server will respond with the last bits of data
117
117
  send_eot
118
118
 
119
+ # After EOT, we wait for 75 seconds for the send queue to be drained and for the
120
+ # server to confirm the last idents. If everything has already been confirmed we can
121
+ # proceed without waiting.
119
122
  @idents_mutex.synchronize do
120
- @logger.write("waiting for last confirm")
121
- # Here, we sleep for 75 seconds while waiting for the send
122
- # queue to be drained and for the server to confirm the last
123
- # idents.
124
- # We are woken up when the unconfirmed_idents is empty, and given back the mutex to
125
- # continue operation.
126
- @empty.wait(@idents_mutex, CONFIRMATION_TIMEOUT) unless @unconfirmed_idents.empty?
123
+ if @unconfirmed_idents.any?
124
+ puts "Waiting for Buildkite Test Analytics to send results..."
125
+ @logger.write("waiting for last confirm")
126
+
127
+ @empty.wait(@idents_mutex, CONFIRMATION_TIMEOUT)
128
+ end
127
129
  end
128
130
 
129
131
  # Then we always disconnect cos we can't wait forever? 🤷‍♀️
130
132
  @connection.close
131
133
  # We kill the write thread cos it's got a while loop in it, so it won't finish otherwise
132
134
  @write_thread&.kill
135
+
136
+ puts "Buildkite Test Analytics completed"
133
137
  @logger.write("socket connection closed")
134
138
  end
135
139
 
@@ -183,6 +187,7 @@ module RSpec::Buildkite::Analytics
183
187
 
184
188
  wait_for_confirm
185
189
 
190
+ puts "Connected to Buildkite Test Analytics!"
186
191
  @logger.write("connected")
187
192
  end
188
193
 
@@ -255,23 +260,21 @@ module RSpec::Buildkite::Analytics
255
260
  @idents_mutex.synchronize do
256
261
  @unconfirmed_idents[ident] = result_as_hash
257
262
 
258
- data = {
263
+ @send_queue << {
259
264
  "action" => "record_results",
260
265
  "results" => [result_as_hash]
261
266
  }
262
-
263
- @send_queue << data
264
267
  end
265
268
  end
266
269
 
267
- def remove_unconfirmed_idents(idents)
268
- return if idents.empty?
270
+ def confirm_idents(idents)
271
+ retransmit_required = @closing
269
272
 
270
273
  @idents_mutex.synchronize do
271
274
  # Remove received idents from unconfirmed_idents
272
275
  idents.each { |key| @unconfirmed_idents.delete(key) }
273
276
 
274
- @logger.write("received confirm for indentifiers: #{idents.join(", ")}")
277
+ @logger.write("received confirm for indentifiers: #{idents}")
275
278
 
276
279
  # This @empty ConditionVariable broadcasts every time that @unconfirmed_idents is
277
280
  # empty, which will happen about every 10mb of data as that's when the server
@@ -281,23 +284,27 @@ module RSpec::Buildkite::Analytics
281
284
  # send the EOT message, so the prior broadcasts shouldn't do anything.
282
285
  if @unconfirmed_idents.empty?
283
286
  @empty.broadcast
284
- @logger.write("broadcast empty")
287
+
288
+ retransmit_required = false
289
+
290
+ @logger.write("all identifiers have been confirmed")
285
291
  else
286
- @logger.write("still waiting on confirm for #{@unconfirmed_idents.keys}")
292
+ @logger.write("still waiting on confirm for identifiers: #{@unconfirmed_idents.keys}")
287
293
  end
288
294
  end
295
+
296
+ # If we're closing, any unconfirmed results need to be retransmitted.
297
+ retransmit if retransmit_required
289
298
  end
290
299
 
291
300
  def send_eot
292
301
  @eot_queued_mutex.synchronize do
293
302
  return if @eot_queued
294
- # Expect server to respond with data of indentifiers last upload part
295
- data = {
303
+
304
+ @send_queue << {
296
305
  "action" => "end_of_transmission",
297
306
  "examples_count" => @examples_count.to_json
298
307
  }
299
-
300
- @send_queue << data
301
308
  @eot_queued = true
302
309
 
303
310
  @logger.write("added EOT to send queue")
@@ -310,7 +317,7 @@ module RSpec::Buildkite::Analytics
310
317
 
311
318
  case
312
319
  when data["message"].key?("confirm")
313
- remove_unconfirmed_idents(data["message"]["confirm"])
320
+ confirm_idents(data["message"]["confirm"])
314
321
  else
315
322
  # unhandled message
316
323
  @logger.write("received unhandled message #{data["message"]}")
@@ -322,13 +329,12 @@ module RSpec::Buildkite::Analytics
322
329
  results = @unconfirmed_idents.values
323
330
 
324
331
  # queue the contents of the buffer, unless it's empty
325
- unless results.empty?
326
- data = {
332
+ if results.any?
333
+ @send_queue << {
327
334
  "action" => "record_results",
328
335
  "results" => results
329
336
  }
330
337
 
331
- @send_queue << data
332
338
  @logger.write("queueing up retransmitted results #{@unconfirmed_idents.keys}")
333
339
  end
334
340
  end
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Buildkite
5
5
  module Analytics
6
- VERSION = "0.8.0"
6
+ VERSION = "0.8.1"
7
7
  NAME = "rspec-buildkite"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-buildkite-analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Buildkite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-25 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport