kevin-j-m / clockwork-test Goto Github PK
View Code? Open in Web Editor NEWA mechanism for testing clockwork jobs
License: MIT License
A mechanism for testing clockwork jobs
License: MIT License
For quite some time, active support has had support for the same functionality Timecop provides.
Furthermore, this project already has dependency on AS, as clockwork is dependent on it.
Would it make sense to remove this dependency?
Also, this will require major release afterwards.
Update the travis configuration to test against:
Rather than overloading the every
and configure
method call in Clockwork itself, Clockwork::Test#run
should parse the file itself to hand off events to Clockwork::Test::Manager
to register.
Hey, @kevin-j-m , could you release a new version of gem?
There are quite some changes in changelog and it would be awesome to have those on rubygems.
Thanks!
I've got a bunch of clockwork tasks which are implemented as database events, as per the docs https://github.com/tomykaira/clockwork#use-with-database-events.
require 'clockwork'
require 'clockwork/database_events'
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
module Clockwork
# required to enable database syncing support
Clockwork.manager = DatabaseEvents::Manager.new
# Update all mailchimp publishers with the latest
# details from the Mailchimp account.
sync_database_events model: PublisherSubscriberSyncClock, every: 1.minute do |model_instance|
# Sync the unsubscribers for the publisher
model_instance.delay(:queue => 'publisher-subscriber-sync').sync_subscribers if model_instance.responds_to?(:sync_subscribers)
end
end
And I'm trying to test against them in the following manor.
# Stage an email publisher in the database.
before(:each) { FactoryGirl.create_list(:email_publisher, 3) }
# Run the clock.
before(:each) { Clockwork::Test.run(file: "#{Rails.root}/lib/clock.rb", max_ticks: 10, tick_speed: 1.minute) }
it "Ran the sync job" do
# Assert that the job was run.
expect(Clockwork::Test.ran_job?('PublisherSubscriberSyncClock')).to be_truthy
end
# Reset the tests after each has run.
after(:each) { Clockwork::Test.clear! }
However these clocks don't appear to be run and my assertions fail. Even when inspecting the job history through Clockwork::Test.manager.send(:history).jobs
they are not listed anywhere, the history is empty.
Traditional non-database jobs are run as expected however.
Right now Clockwork::Test
can check if the schedule that's been written is performing as expected. This should be extended to test if the handler that's written to run at that particular schedule is also working correctly.
EVERY_TEN_FULL_MINUTES = [
"**:00",
"**:10",
"**:20",
"**:30",
"**:40",
"**:50"
].freeze
every(1.hour, TestJob.name, at: EVERY_TEN_FULL_MINUTES, tz: "UTC") { }
# start at beginning of day to ensure we match the ten full minutes
now = Time.current.in_time_zone("UTC")
start_at = now.beginning_of_day
Clockwork::Test.run(max_ticks: 3, start_at: start_at, tick_speed: 30.minutes)
assert_equal(2, Clockwork::Test.times_run(TestJob.name))
rails test test/config/clockwork_test.rb:21
Running via Spring preloader in process 20916
Run options: --seed 52425
# Running:
F
Failure:
ClockworkTest#test_test_job [test/config/clockwork_test.rb:28]:
Expected: 2
Actual: 0
I believe this commit broke the wrapping logic for the Clockwork::Test::Manager class
I'm using database backed events in a clockwork implementation, and I'm trying use this gem with rspec. However, nothing happens. It seems that the event getting fetched from the database, and not using the correct every
that this gem has overridden. It seems like the current version of ClockworkTest is not compatible with database backed events. If I'm wrong, is there a different setup for this gem that is not documented when using database backed events.
Update the Travis CI configuration to test against ruby 2.5.
Here is my clockwork file:
every(1.day, "available pl margin updater job", :at => "00:00") do
AvailablePlMarginUpdaterJob.perform_later
end
And here is the spec:
it "runs AvailablePlMarginUpdaterJob every day over the course of six days" do
Time.use_zone("Asia/Bangkok") do
start_time = Time.zone.local(2015, 11, 2, 23, 0, 0)
end_time = Time.zone.local(2015, 11, 7, 23, 59, 0)
Clockwork::Test.run(start_time: start_time, end_time: end_time, tick_speed: 1.day)
expect(Clockwork::Test.times_run("available pl margin updater job")).to eq 5
end
end
If I run the test, it failed with:
Failure/Error: expect(Clockwork::Test.times_run("available pl margin updater job")).to eq 5
expected: 5
got: 0
It runs ok if I remove the at:
option from the clockwork file.
I follow the spec files in this repo but couldn't find any more info to help with this problem.
Thank you very much for your help, I really appreciate that.
I have 2 clock instances (2 clock.rb files: clock.rb
&& clock_business_logic_xyz.rb
). Everything
runs OK but I am not sure how to rspec test both of them.
All tests are checking only tasks in clock.rb
file.
Any ideas?
If location of clock.rb
is not config
, specs fail. Shouldn't this be more flexible?
Failures:
1) Clockwork runs the test one time
Failure/Error: Clockwork::Test.run(max_ticks: 1)
LoadError:
cannot load such file -- ./config/clock.rb
# ./spec/clock_spec.rb:7:in `block (2 levels) in <top (required)>'
Perhaps due to the way it is requiring the clockwork configuration file:
config/clock.rb:9: warning: previous definition of EVERY_TEN_FULL_MINUTES was here
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.