Sha256: b8ef94009c9aca0ec5d56a762fb1a1d74098b5532673c80727d838aadc54f969

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require "test_helper"

class TestJob < Minitest::Test
  def default_config
    @default_config ||= {
      redis: Redis.new,
      logger: logger,
      long_running_timeout: 5.minutes
    }
  end

  def logger
    @logger ||= begin
      l = Logger.new(STDOUT)
      l.level = Logger::UNKNOWN
      l
    end
  end

  def test_initialize
    job = Zhong::Job.new("test_initialize", {at: "12:00"}.merge(default_config))

    assert job
    assert !job.running?
    assert_equal "test_initialize", job.to_s
  end

  def test_should_run
    sleep 1

    job = Zhong::Job.new("test_should_run", {every: 1.second}.merge(default_config))

    assert_equal true, job.run?
  end

  def test_run
    success_counter = Queue.new
    job = Zhong::Job.new("test_run", {every: 1.second}.merge(default_config)) { success_counter << 1 }
    now = Time.now

    assert_equal 0, success_counter.size
    assert_equal true, job.run?(now)
    job.run(now)
    assert_equal false, job.run?(now)
    assert_equal 1, success_counter.size
  end

  def test_disable
    success_counter = Queue.new
    job = Zhong::Job.new("test_disable", {every: 1.second}.merge(default_config)) { success_counter << 1 }
    now = Time.now

    job.disable

    assert_equal true, job.run?(now)
    job.run(now)
    assert_equal true, job.run?(now)
    assert_equal 0, success_counter.size
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zhong-0.1.5 test/job_test.rb