Skip to content

fix(blocking-api): fixed issue related to default blocking-timeout and blocking API methods. #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 20, 2019

Conversation

rashidsp
Copy link
Contributor

@rashidsp rashidsp commented Sep 11, 2019

Summary

  • Fixed bug when blocking_timeout is set to default.
  • Block all APIs for the blocking_timeout period or datafile is not loaded successfulsy.
  • Updated doc string.

@rashidsp rashidsp requested a review from a team as a code owner September 11, 2019 14:53
@msohailhussain msohailhussain added the WIP Work in progress label Sep 11, 2019
@msohailhussain msohailhussain changed the title fix(blocking-timeout): fixed issue related to default blocking-timeout. fix(blocking-timeout): fixed issue related to default blocking-timeout. - WIP Sep 11, 2019
@coveralls
Copy link

coveralls commented Sep 11, 2019

Coverage Status

Coverage decreased (-0.02%) to 99.432% when pulling 3570990 on rashid/dfm-blocking-timeout into 7ab4650 on master.

@@ -39,5 +38,9 @@ def initialize(datafile, logger, error_handler, skip_json_validation)
skip_json_validation
)
end

def get_config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this should be defined in the projectconfigmanager as an abstract method. right now i can see config is defined in the projectconfig manager.

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please respond to get_config, rest of the stuff will review after that.

@msohailhussain msohailhussain removed the WIP Work in progress label Sep 11, 2019
@msohailhussain msohailhussain changed the title fix(blocking-timeout): fixed issue related to default blocking-timeout. - WIP fix(blocking-timeout): fixed issue related to default blocking-timeout. Sep 11, 2019
@msohailhussain msohailhussain changed the title fix(blocking-timeout): fixed issue related to default blocking-timeout. fix(blocking-api): fixed issue related to default blocking-timeout and blocking API methods. Sep 11, 2019
# Get Project Config.

# If the background datafile polling thread is running. and config has been initalized,
# we simply return config.
# If it is not, we wait and block maximum for @blocking_timeout.
# If thread is not running, we fetch the datafile and update config.
return nil if @closed == true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to return nil in this case? Is there a problem with just returning the current @config? Also, why @closed == true instead of @closed?

@@ -243,7 +245,7 @@ def blocking_timeout(blocking_timeout)
Logger::DEBUG,
"Blocking timeout is not provided. Defaulting to #{Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT']} seconds."
)
@polling_interval = Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT']
@blocking_timeout = Helpers::Constants::CONFIG_MANAGER['DEFAULT_BLOCKING_TIMEOUT']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that there is test coverage that would have revealed these places where it should have been @blocking_timeout, but was actually @polling_interval.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -105,13 +105,15 @@ def stop!
@closed = true
end

def get_config
def config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you are defining config not get_config, unable to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following ruby's convention.
Please view rubocop's rule https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/AccessorMethodName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumpled upon this, too. Not even your own StaticProjectConfigManager is using get_config which makes it unusable here:

@config_manager = if config_manager.respond_to?(:get_config)
config_manager
elsif sdk_key
HTTPProjectConfigManager.new(

@rashidsp rashidsp added WIP Work in progress and removed WIP Work in progress labels Sep 13, 2019
@mjc1283
Copy link

mjc1283 commented Sep 17, 2019

@msohailhussain Could you please review and approve if this looks good to you?

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. please address minor nits.

# Get Project Config.

# If the background datafile polling thread is running. and config has been initalized,
# we simply return config.
# If it is not, we wait and block maximum for @blocking_timeout.
# If thread is not running, we fetch the datafile and update config.
return @config if @closed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjc1283 I think, better attribute name is stopped, since function name is stop. Do you suggest to rename it?
@rashidsp can you please add a comment here, if closed is true, then config is set to nil.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msohailhussain I agree that stopped is a better attribute name.

README.md Outdated
@@ -44,7 +44,7 @@ You can initialize the Optimizely instance in two ways: directly with a datafile

When the `datafile` is given then it will be used initially before any update.

2. Initialize Optimizely by providing a Config Manager that implements a 'get_config' method. You can customize our `HTTPConfigManager` as needed.
2. Initialize Optimizely by providing a Config Manager that implements a 'config' method. You can customize our `HTTPConfigManager` as needed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use config

@@ -362,7 +362,7 @@ module Constants

CONFIG_MANAGER = {
'DATAFILE_URL_TEMPLATE' => 'https://cdn.optimizely.com/datafiles/%s.json',
# Default time in seconds to block the get_config call until config has been initialized.
# Default time in seconds to block the config method call until config has been initialized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config or 'config'

@@ -29,7 +29,7 @@ def self.default_instance(sdk_key, datafile = nil)

# Returns a new optimizely instance.
#
# @param config_manager - Required ConfigManagerInterface Responds to get_config.
# @param config_manager - Required ConfigManagerInterface Responds to config method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please single quote. am saying config should be more focused as method name.

@mjc1283 mjc1283 closed this Sep 19, 2019
@mjc1283 mjc1283 reopened this Sep 19, 2019
@mjc1283 mjc1283 merged commit 2d0b8b3 into master Sep 20, 2019
@rashidsp rashidsp deleted the rashid/dfm-blocking-timeout branch September 23, 2019 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants