Skip to content

Commit 8784a7e

Browse files
committed
don't create new update processor is already started
1 parent 473de38 commit 8784a7e

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

lib/ldclient-rb/impl/datasource/null_processor.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module DataSource
77
# A minimal UpdateProcessor implementation used when the SDK is in offline mode
88
# or daemon (LDD) mode. It does nothing except mark itself as initialized.
99
#
10-
# @private
11-
#
1210
class NullUpdateProcessor
1311
include LaunchDarkly::Interfaces::DataSource
1412

lib/ldclient-rb/impl/datasystem/fdv1.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ module DataSystem
1212
# FDv1 wires the existing v1 data source and store behavior behind the
1313
# generic DataSystem surface.
1414
#
15-
# @private
16-
#
1715
class FDv1
1816
include LaunchDarkly::Impl::DataSystem
1917

@@ -63,7 +61,7 @@ def initialize(sdk_key, config)
6361
# Ensure v1 processors can find the sink via config for status updates
6462
@config.data_source_update_sink = @data_source_update_sink
6563

66-
# Update processor created in start(), because it needs the ready event
64+
# Update processor created in start()
6765
@update_processor = nil
6866

6967
# Diagnostic accumulator provided by client for streaming metrics
@@ -74,15 +72,20 @@ def initialize(sdk_key, config)
7472
# Starts the v1 update processor and returns immediately. The returned event
7573
# will be set by the processor upon first successful initialization or upon permanent failure.
7674
#
75+
# If called multiple times, returns the same event as the first call. The update
76+
# processor is created only once, and subsequent calls delegate to the processor's
77+
# own start method which handles multiple invocations.
78+
#
7779
# @return [Concurrent::Event] Event that will be set when initialization is complete
7880
#
7981
def start
80-
@update_processor = make_update_processor
82+
@update_processor ||= make_update_processor
8183
@update_processor.start
8284
end
8385

8486
#
85-
# Halts the data system, stopping the update processor and shutting down the executor.
87+
# Halts the data system, stopping the update processor and shutting down the executor,
88+
# making the data system no longer usable.
8689
#
8790
# @return [void]
8891
#

lib/ldclient-rb/impl/integrations/test_data/test_data_source.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module LaunchDarkly
55
module Impl
66
module Integrations
77
module TestData
8-
# @private
98
class TestDataSource
109
include LaunchDarkly::Interfaces::DataSource
1110

spec/impl/datasystem/fdv1_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ module DataSystem
9595
expect(ready_event).to be_a(Concurrent::Event)
9696
end
9797
end
98+
99+
it "returns the same event on multiple calls" do
100+
first_event = subject.start
101+
second_event = subject.start
102+
third_event = subject.start
103+
104+
expect(second_event).to be(first_event)
105+
expect(third_event).to be(first_event)
106+
end
107+
108+
it "does not create a new processor on subsequent calls" do
109+
processor = MockUpdateProcessor.new
110+
allow(subject).to receive(:make_update_processor).and_return(processor)
111+
112+
subject.start
113+
expect(subject).to have_received(:make_update_processor).once
114+
115+
subject.start
116+
subject.start
117+
# Should still only be called once
118+
expect(subject).to have_received(:make_update_processor).once
119+
end
98120
end
99121

100122
describe "#stop" do

0 commit comments

Comments
 (0)