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

A public method to clear cached circuits in tests #173

Open
fabioperrella opened this issue Jul 9, 2021 · 4 comments
Open

A public method to clear cached circuits in tests #173

fabioperrella opened this issue Jul 9, 2021 · 4 comments

Comments

@fabioperrella
Copy link

Hi!

It would be great to have a public method where we can clear cached circuits to use before each test run.

Today, one test can open a circuit and then it can cause failures in many others that use the same circuit.

This gets in the way to find the real culprit.

What about turning the method Circuitbox.clear_cached_circuits! into a public one?

@matthewshafer
Copy link
Collaborator

Time permitting, I'll have this change merged in the next few days. Not sure if I'll keep the same method name or change it a bit.

@a-maas
Copy link

a-maas commented Mar 20, 2024

+1. I tried the code in the 2.0 upgrading doc when reset was deprecated, but it doesn't seem to reset between tests.

Circuitbox.configure do |config|
  config.default_circuit_store = Circuitbox::MemoryStore.new
end

@matthewshafer
Copy link
Collaborator

matthewshafer commented Apr 2, 2024

+1. I tried the code in the 2.0 upgrading doc when reset was deprecated, but it doesn't seem to reset between tests.

Circuitbox.configure do |config|
  config.default_circuit_store = Circuitbox::MemoryStore.new
end

I haven't run into circuitbox not resetting circuit's after a configuration change when circuits are accessed through Circuitbox.circuit.

I put together a small minitest suite using what's described in the upgrade guide and reset appears to be working.

require 'minitest'
require 'circuitbox'

class CircuitboxResetTest < Minitest::Test
  def setup
    Circuitbox.configure do |config|
      config.default_circuit_store = Circuitbox::MemoryStore.new
    end
  end

  def test_circuit_one
    runs = 0

    5.times do
      circuit_fail do
        runs += 1
      end
    end

    assert_equal 2, runs
  end

  def test_circuit_two
    runs = 0

    5.times do
      circuit_fail do
        runs += 1
      end
    end

    assert_equal 2, runs
  end

  def circuit_fail
    Circuitbox.circuit(:test, exceptions: [StandardError], volume_threshold: 2) do
      yield
      raise StandardError
    end
  end
end

Minitest.run

I've run that a few times and haven't run into any failures. Once I remove the tests setup failures start to show up as the circuit state is being leaked across tests.

If you're running into issues could you put something together that reproduces circuits not being reset?

@a-maas
Copy link

a-maas commented Apr 2, 2024

Thanks @matthewshafer. I went back and reviewed it, and your example test helped me uncover an issue where I wasn't calling the reset enough.

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