Skip to content

Commit 5d3c74d

Browse files
oakbaniMichael Ng
authored andcommitted
refact: Revise unit tests for http config manager (#214)
1 parent e3bce0e commit 5d3c74d

File tree

2 files changed

+151
-106
lines changed

2 files changed

+151
-106
lines changed

lib/optimizely/config_manager/http_project_config_manager.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ def initialize(
7070
@blocking_timeout = nil
7171
blocking_timeout(blocking_timeout)
7272
@last_modified = nil
73-
@async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger)
74-
@async_scheduler.start! if start_by_default == true
75-
@stopped = false
7673
@skip_json_validation = skip_json_validation
7774
@notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(@logger, @error_handler)
7875
@config = datafile.nil? ? nil : DatafileProjectConfig.create(datafile, @logger, @error_handler, @skip_json_validation)
7976
@mutex = Mutex.new
8077
@resource = ConditionVariable.new
78+
@async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger)
79+
# Start async scheduler in the end to avoid race condition where scheduler executes
80+
# callback which makes use of variables not yet initialized by the main thread.
81+
@async_scheduler.start! if start_by_default == true
82+
@stopped = false
8183
end
8284

8385
def ready?

0 commit comments

Comments
 (0)