GithubHelp home page GithubHelp logo

clockwork-test's People

Contributors

aprescott avatar bencolon avatar brain-geek avatar felix-dumit avatar kevin-j-m avatar rahul342 avatar robinbrandt avatar tiendo1011 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

clockwork-test's Issues

Migrating from Timecop to ActiveSupport time travel

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.

Load up test events by reading file

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.

Release new version

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!

Support for Database Events

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.

Test handler as well as schedule

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.

Wildcards for times not supported?

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

Clockwork::DatabaseEvents

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.

times_run doesn't count when using at: option

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.

Testing 2 clock instances

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?

Forces `config/clock.rb`

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)>'

Redefining constants

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.