Sha256: e23687cc1c0c4cbd906f156f778e301cca367009c00c47995cc3bb21c60b7229

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

require "test_helper"
require "faraday"
require "circuitbox/faraday_middleware"
require "rack"

class FakeServer
  def self.instance
    @@instance ||= FakeServer.new
    # if the FakeServer is used kill all of them after the tests are done
    Minitest.after_run { FakeServer.shutdown }
    @@instance
  end

  def initialize
    @servers = []
  end

  def self.create(port, result)
    FakeServer.instance.create(port, result)
  end

  def self.shutdown
    FakeServer.instance.shutdown
  end

  def shutdown
    @servers.map { |server| server.exit }
    @servers = []
  end

  def create(port, result)
    @servers << Thread.new do
      Rack::Handler::WEBrick.run(Proc.new { |env| result },
                                 Port: port,
                                 AccessLog: [],
                                 Logger: WEBrick::Log.new(DEV_NULL))
    end
    sleep 0.5 # wait for the server to spin up
  end
end

module IntegrationHelpers
  def open_circuit
    volume_threshold = Circuitbox['test'].option_value(:volume_threshold)
    (volume_threshold + 1).times { connection.get(failure_url) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
circuitbox-0.10.4 test/integration_helper.rb
circuitbox-0.10.3 test/integration_helper.rb
circuitbox-0.10.2 test/integration_helper.rb
circuitbox-0.10.1 test/integration_helper.rb