class Sidekiq::Testing

Attributes

__global_test_mode[RW]

Public Class Methods

__local_test_mode() click to toggle source
# File lib/sidekiq/testing.rb, line 36
def __local_test_mode
  Thread.current[:__sidekiq_test_mode]
end
__local_test_mode=(value) click to toggle source
# File lib/sidekiq/testing.rb, line 40
def __local_test_mode=(value)
  Thread.current[:__sidekiq_test_mode] = value
end
__set_test_mode(mode) { || ... } click to toggle source

Calling without a block sets the global test mode, affecting all threads. Calling with a block only affects the current Thread.

# File lib/sidekiq/testing.rb, line 14
def __set_test_mode(mode)
  if block_given?
    # Reentrant testing modes will lead to a rat's nest of code which is
    # hard to reason about. You can set the testing mode once globally and
    # you can override that global setting once per-thread.
    raise TestModeAlreadySetError, "Nesting test modes is not supported" if __local_test_mode

    self.__local_test_mode = mode
    begin
      yield
    ensure
      self.__local_test_mode = nil
    end
  else
    self.__global_test_mode = mode
  end
end
__test_mode() click to toggle source
# File lib/sidekiq/testing.rb, line 32
def __test_mode
  __local_test_mode || __global_test_mode
end
disable!(&block) click to toggle source
# File lib/sidekiq/testing.rb, line 44
def disable!(&block)
  __set_test_mode(:disable, &block)
end
disabled?() click to toggle source
# File lib/sidekiq/testing.rb, line 60
def disabled?
  __test_mode == :disable
end
enabled?() click to toggle source
# File lib/sidekiq/testing.rb, line 56
def enabled?
  __test_mode != :disable
end
fake!(&block) click to toggle source
# File lib/sidekiq/testing.rb, line 48
def fake!(&block)
  __set_test_mode(:fake, &block)
end
fake?() click to toggle source
# File lib/sidekiq/testing.rb, line 64
def fake?
  __test_mode == :fake
end
inline!(&block) click to toggle source
# File lib/sidekiq/testing.rb, line 52
def inline!(&block)
  __set_test_mode(:inline, &block)
end
inline?() click to toggle source
# File lib/sidekiq/testing.rb, line 68
def inline?
  __test_mode == :inline
end
server_middleware() { |server_chain| ... } click to toggle source
# File lib/sidekiq/testing.rb, line 72
def server_middleware
  @server_chain ||= Middleware::Chain.new(Sidekiq.default_configuration)
  yield @server_chain if block_given?
  @server_chain
end