Skip to content

Commit

Permalink
Test passing the scheduled time and not passing the time into jobs an…
Browse files Browse the repository at this point in the history
…d workers
  • Loading branch information
brianpattison committed Dec 8, 2016
1 parent 2c60cce commit 958a355
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 77 deletions.
4 changes: 2 additions & 2 deletions config/simple_scheduler.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Example file used by scheduler_job_spec.rb as the default config path.
job_one:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.week"
at: "Sun 1:00"

job_two:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.week"
at: "Sun 1:00"
1 change: 0 additions & 1 deletion simple_scheduler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ Gem::Specification.new do |s|
s.add_development_dependency "rubocop"
s.add_development_dependency "simplecov"
s.add_development_dependency "simplecov-rcov"
s.add_development_dependency "timecop"
end
4 changes: 0 additions & 4 deletions spec/dummy/app/jobs/simple_scheduler_test_job.rb

This file was deleted.

4 changes: 4 additions & 0 deletions spec/dummy/app/jobs/test_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Active Job for testing
class TestJob < ApplicationJob
def perform(scheduled_time); end
end
4 changes: 4 additions & 0 deletions spec/dummy/app/jobs/test_no_args_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Active Job for testing a job with no args
class TestNoArgsJob < ApplicationJob
def perform; end
end
5 changes: 5 additions & 0 deletions spec/dummy/app/jobs/test_no_args_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Sidekiq Worker for testing a worker with no args
class TestNoArgsWorker
include Sidekiq::Worker
def perform; end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Sidekiq Worker for testing
class SimpleSchedulerTestWorker
class TestWorker
include Sidekiq::Worker
def perform(time); end
def perform(scheduled_time); end
end
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "spec_helper"
require "rspec/rails"
require "timecop"

RSpec.configure do |config|
config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers
config.filter_rails_from_backtrace!
end
2 changes: 1 addition & 1 deletion spec/simple_scheduler/config/active_job.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
weekly_task:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.week"
at: "Sun 1:00"
2 changes: 1 addition & 1 deletion spec/simple_scheduler/config/hourly_task.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hourly_task:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.hour"
at: "*:00"
2 changes: 1 addition & 1 deletion spec/simple_scheduler/config/queue_ahead_global.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
queue_ahead: 120

hourly_task:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.hour"
at: "*:00"
2 changes: 1 addition & 1 deletion spec/simple_scheduler/config/queue_ahead_per_task.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hourly_task:
class: "SimpleSchedulerTestJob"
class: "TestJob"
every: "1.hour"
at: "*:00"
queue_ahead: 180
2 changes: 1 addition & 1 deletion spec/simple_scheduler/config/sidekiq_worker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
weekly_task:
class: "SimpleSchedulerTestWorker"
class: "TestWorker"
every: "1.week"
at: "Sun 1:00"
54 changes: 49 additions & 5 deletions spec/simple_scheduler/future_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
describe "when an Active Job is scheduled" do
let(:task_params) do
{
class: "SimpleSchedulerTestJob",
class: "TestJob",
every: "1.hour",
name: "job_task"
}
Expand All @@ -34,7 +34,7 @@
describe "when a Sidekiq Worker is scheduled" do
let(:task_params) do
{
class: "SimpleSchedulerTestWorker",
class: "TestWorker",
every: "1.hour",
name: "worker_task"
}
Expand All @@ -43,14 +43,58 @@
it "adds the job to the queue" do
expect do
described_class.perform_now(task_params, Time.now.to_i)
end.to change(SimpleSchedulerTestWorker.jobs, :size).by(1)
end.to change(TestWorker.jobs, :size).by(1)
end
end

describe "when a job or worker accepts the scheduled time as an argument" do
it "executes an Active Job without exception" do
expect do
task_params = { class: "TestJob", every: "1.hour" }
perform_enqueued_jobs do
described_class.perform_now(task_params, Time.now.to_i)
end
end.not_to raise_error
end

it "executes an Sidekiq Worker without exception" do
expect do
task_params = { class: "TestWorker", every: "1.hour" }
perform_enqueued_jobs do
Sidekiq::Testing.inline! do
described_class.perform_now(task_params, Time.now.to_i)
end
end
end.not_to raise_error
end
end

describe "when a job or worker accepts no arguments" do
it "executes an Active Job without exception" do
expect do
task_params = { class: "TestNoArgsJob", every: "1.hour" }
perform_enqueued_jobs do
described_class.perform_now(task_params, Time.now.to_i)
end
end.not_to raise_error
end

it "executes an Sidekiq Worker without exception" do
expect do
task_params = { class: "TestNoArgsWorker", every: "1.hour" }
perform_enqueued_jobs do
Sidekiq::Testing.inline! do
described_class.perform_now(task_params, Time.now.to_i)
end
end
end.not_to raise_error
end
end

describe "when the job is run within the allowed expiration time" do
let(:task_params) do
{
class: "SimpleSchedulerTestJob",
class: "TestJob",
every: "1.hour",
name: "job_task",
expires_after: "30.minutes"
Expand All @@ -67,7 +111,7 @@
describe "when the job is run past the allowed expiration time" do
let(:task_params) do
{
class: "SimpleSchedulerTestJob",
class: "TestJob",
every: "1.hour",
name: "job_task",
expires_after: "30.minutes"
Expand Down
Loading

0 comments on commit 958a355

Please sign in to comment.