From e16a3f23504e893c54ba99047f02876af14f512f Mon Sep 17 00:00:00 2001 From: jsonbailey Date: Fri, 23 Jan 2026 14:57:26 +0000 Subject: [PATCH 1/2] chore: Additional testing of diagnostic events --- .../streaming_synchronizer_spec.rb | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/spec/impl/data_system/streaming_synchronizer_spec.rb b/spec/impl/data_system/streaming_synchronizer_spec.rb index e695d48b..a6c2f948 100644 --- a/spec/impl/data_system/streaming_synchronizer_spec.rb +++ b/spec/impl/data_system/streaming_synchronizer_spec.rb @@ -310,6 +310,93 @@ def initialize(type, data = nil) expect(update.change_set.changes[0].action).to eq(LaunchDarkly::Interfaces::DataSystem::ChangeType::DELETE) end end + + describe 'diagnostic event recording' do + let(:synchronizer) { StreamingDataSource.new(sdk_key, config) } + + it "logs successful connection when diagnostic_accumulator is provided" do + diagnostic_accumulator = double("DiagnosticAccumulator") + expect(diagnostic_accumulator).to receive(:record_stream_init).with( + kind_of(Integer), + false, + kind_of(Integer) + ) + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + synchronizer.send(:log_connection_started) + synchronizer.send(:log_connection_result, true) + end + + it "logs failed connection when diagnostic_accumulator is provided" do + diagnostic_accumulator = double("DiagnosticAccumulator") + expect(diagnostic_accumulator).to receive(:record_stream_init).with( + kind_of(Integer), + true, + kind_of(Integer) + ) + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + synchronizer.send(:log_connection_started) + synchronizer.send(:log_connection_result, false) + end + + it "logs connection metrics with correct timestamp and duration" do + diagnostic_accumulator = double("DiagnosticAccumulator") + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + + expect(diagnostic_accumulator).to receive(:record_stream_init) do |timestamp, failed, duration| + expect(timestamp).to be_a(Integer) + expect(timestamp).to be > 0 + expect(failed).to eq(false) + expect(duration).to be_a(Integer) + expect(duration).to be >= 0 + end + + synchronizer.send(:log_connection_started) + sleep(0.01) # Small delay to ensure measurable duration + synchronizer.send(:log_connection_result, true) + end + + it "only logs once per connection attempt" do + diagnostic_accumulator = double("DiagnosticAccumulator") + expect(diagnostic_accumulator).to receive(:record_stream_init).once + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + synchronizer.send(:log_connection_started) + synchronizer.send(:log_connection_result, true) + + # Second call should not record again (no new connection_started) + synchronizer.send(:log_connection_result, true) + end + + it "does not log when diagnostic_accumulator is not set" do + # Should not raise an error + expect { synchronizer.send(:log_connection_started) }.not_to raise_error + expect { synchronizer.send(:log_connection_result, true) }.not_to raise_error + end + + it "does not log when connection was not started" do + diagnostic_accumulator = double("DiagnosticAccumulator") + expect(diagnostic_accumulator).not_to receive(:record_stream_init) + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + # Call log_connection_result without log_connection_started + synchronizer.send(:log_connection_result, true) + end + + it "resets connection attempt time after logging" do + diagnostic_accumulator = double("DiagnosticAccumulator") + expect(diagnostic_accumulator).to receive(:record_stream_init).once + + synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) + synchronizer.send(:log_connection_started) + synchronizer.send(:log_connection_result, true) + + # Another log_connection_result should not record (time was reset) + synchronizer.send(:log_connection_result, true) + end + end end end end From 820e4f0d50a0ce814634760b3c86ab00288e7058 Mon Sep 17 00:00:00 2001 From: jsonbailey Date: Fri, 23 Jan 2026 18:23:31 +0000 Subject: [PATCH 2/2] remove redundant test --- spec/impl/data_system/streaming_synchronizer_spec.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/spec/impl/data_system/streaming_synchronizer_spec.rb b/spec/impl/data_system/streaming_synchronizer_spec.rb index c783556c..87d256fe 100644 --- a/spec/impl/data_system/streaming_synchronizer_spec.rb +++ b/spec/impl/data_system/streaming_synchronizer_spec.rb @@ -384,18 +384,6 @@ def initialize(type, data = nil) # Call log_connection_result without log_connection_started synchronizer.send(:log_connection_result, true) end - - it "resets connection attempt time after logging" do - diagnostic_accumulator = double("DiagnosticAccumulator") - expect(diagnostic_accumulator).to receive(:record_stream_init).once - - synchronizer.set_diagnostic_accumulator(diagnostic_accumulator) - synchronizer.send(:log_connection_started) - synchronizer.send(:log_connection_result, true) - - # Another log_connection_result should not record (time was reset) - synchronizer.send(:log_connection_result, true) - end end end end