Skip to content

Commit 3245c24

Browse files
prepare 5.6.2 release (#146)
1 parent 00e2079 commit 3245c24

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/ldclient-rb/events.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "concurrent"
22
require "concurrent/atomics"
33
require "concurrent/executors"
4+
require "securerandom"
45
require "thread"
56
require "time"
67

@@ -359,6 +360,7 @@ def run(sdk_key, config, client, payload, formatter)
359360
events_out = formatter.make_output_events(payload.events, payload.summary)
360361
res = nil
361362
body = events_out.to_json
363+
payload_id = SecureRandom.uuid
362364
(0..1).each do |attempt|
363365
if attempt > 0
364366
config.logger.warn { "[LDClient] Will retry posting events after 1 second" }
@@ -374,6 +376,7 @@ def run(sdk_key, config, client, payload, formatter)
374376
req["Authorization"] = sdk_key
375377
req["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
376378
req["X-LaunchDarkly-Event-Schema"] = CURRENT_SCHEMA_VERSION.to_s
379+
req["X-LaunchDarkly-Payload-ID"] = payload_id
377380
req["Connection"] = "keep-alive"
378381
res = client.request(req)
379382
rescue StandardError => exn

spec/events_spec.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,29 @@
416416
expect(hc.get_request["authorization"]).to eq "sdk_key"
417417
end
418418

419+
it "sends unique payload IDs" do
420+
@ep = subject.new("sdk_key", default_config, hc)
421+
e = { kind: "identify", user: user }
422+
423+
@ep.add_event(e)
424+
@ep.flush
425+
@ep.wait_until_inactive
426+
req0 = hc.get_request
427+
428+
@ep.add_event(e)
429+
@ep.flush
430+
@ep.wait_until_inactive
431+
req1 = hc.get_request
432+
433+
id0 = req0["x-launchdarkly-payload-id"]
434+
id1 = req1["x-launchdarkly-payload-id"]
435+
expect(id0).not_to be_nil
436+
expect(id0).not_to eq ""
437+
expect(id1).not_to be nil
438+
expect(id1).not_to eq ""
439+
expect(id1).not_to eq id0
440+
end
441+
419442
def verify_unrecoverable_http_error(status)
420443
@ep = subject.new("sdk_key", default_config, hc)
421444
e = { kind: "identify", user: user }
@@ -442,8 +465,15 @@ def verify_recoverable_http_error(status)
442465
@ep.flush
443466
@ep.wait_until_inactive
444467

445-
expect(hc.get_request).not_to be_nil
446-
expect(hc.get_request).not_to be_nil
468+
req0 = hc.get_request
469+
expect(req0).not_to be_nil
470+
req1 = hc.get_request
471+
expect(req1).not_to be_nil
472+
id0 = req0["x-launchdarkly-payload-id"]
473+
expect(id0).not_to be_nil
474+
expect(id0).not_to eq ""
475+
expect(req1["x-launchdarkly-payload-id"]).to eq id0
476+
447477
expect(hc.get_request).to be_nil # no 3rd request
448478

449479
# now verify that a subsequent flush still generates a request

0 commit comments

Comments
 (0)