Sha256: 2e44f324b084a0512e3e05b4464b6ef867edc1b29f1638d94303d3e2c067d41d

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'minitest/unit'
require 'minitest/autorun'
$:<< File.dirname(__FILE__) + "/../lib"
require 'localjob'
require "mocha/setup"
require 'jobs'

class LocaljobTestCase < MiniTest::Unit::TestCase
  protected
  # This is a method to make sure the logger is set right.
  def worker(queues = ["/localjob-test"])
    Localjob::Worker.new(queues, logger: logger)
  end

  # This is a method to make sure all queues are registred and destroyed after
  # each teach run.
  def queue(name = "/localjob-test")
    @queues ||= []
    queue = Localjob.new(name)
    @queues << queue
    queue
  end

  def teardown
    clear_queue
  end

  def logger
    return @logger if @logger

    output_file = ENV["DEBUG"] ? STDOUT : "/dev/null"
    @logger = Logger.new(output_file)
  end

  def clear_queue
    @queues.each(&:destroy) if @queues

    # This forces the GC to garbage collect, and thus close file descriptioners
    # in POSIX::Mqueue. Otherwise we'll get flooded with warnings. This is to
    # ensure a clean state everytime with a new message queue for each test.
    # It's slower. But safe.
    GC.start
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localjob-0.0.1 test/test_helper.rb