Skip to content
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

Testing with Feature.run_with_activated(:feature_name) has no effect under certain circumstances. #53

Open
edelgado opened this issue Feb 12, 2018 · 2 comments

Comments

@edelgado
Copy link

edelgado commented Feb 12, 2018

Howdy,

Given a feature.yml file with the following snippet:

test:
  features:
    feature_name: false

Using Feature.run_with_activated within a RSpec example like so:

it 'does something' do
  Feature.run_with_activated(:feature_name) do
    # The test, `feature_name` here is disabled. Expected it to be enabled even if `feature.yml` has it as `false` for the test environment.
    Feature.active? 'feature_name' # false
  end
end

does not actually run the code with feature_name active.

Any ideas?

@edelgado edelgado changed the title Testing with Feature.run_with_activated(:feature_name) has no effect Testing with Feature.run_with_activated(:feature_name) has no effect under certain circumstances. Feb 12, 2018
@will3216
Copy link
Contributor

Based on your example, it might be the difference between using a string vs a symbol?

@alexeymorozov
Copy link

Do you use 'Feature-toggle caching' with a number as a second argument?

Feature.set_repository(your_repository, 60)

If yes, it could happen because #run_with_activated doesn't flush @next_refresh_after:

  def self.run_with_activated(*features, &blk)
    with_stashed_config do
      @active_features.concat(features).uniq!
      @auto_refresh = false
      @perform_initial_refresh = false
      blk.call
    end
  end

And #active_features refreshes features from a repo:

  def self.active_features
    raise 'missing Repository for obtaining feature lists' unless @repository

    refresh! if @auto_refresh || @perform_initial_refresh || (@next_refresh_after && Time.now > @next_refresh_after)

    @active_features
  end

  def self.refresh!
    @active_features = @repository.active_features
    @next_refresh_after = Time.now + @refresh_after if @refresh_after
    @perform_initial_refresh = false
  end

There is another condition for a bug to be reproduced:

  • specs should be executed for more than @refresh_time
  • or spring should be started before (Time.now - @refresh_time).

Both easily happen if @refresh_time is pretty small.

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

No branches or pull requests

3 participants