kevin-j-m / clockwork-test

A mechanism for testing clockwork jobs
MIT License
43 stars 15 forks source link

Wildcards for times not supported? #31

Closed ce07c3 closed 4 years ago

ce07c3 commented 6 years ago
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
kevin-j-m commented 6 years ago

Hi! I pushed a branch validating clockwork test picking up wildcard values in the at: option. This spec is passing for me.

The tick_speed might be causing issues for you, though I'd expect that to pick up the job 3 times (at 00:00, 00:300, and 1:00, the three clock ticks you'd get), but I'm not certain/obviously that's not the case.

Perhaps you can use that test case as a guide?

EDIT: here's a link to the test I'm referencing, as the branch referenced above was merged.

ce07c3 commented 6 years ago

Sure, I'll check it out! 👍

kevin-j-m commented 6 years ago

Was that commit helpful to you in resolving your issue?

ce07c3 commented 6 years ago

The commit is gone, but I can see the branch was merged and deleted. I'll check off master now.

ce07c3 commented 6 years ago

Still having the same issues.

kevin-j-m commented 6 years ago

I've recreated your exact scenario in another branch, given in rspec, not minitest.

There are two commits:

  1. The first sets the ticks and clock speed as you have it, and if verifies that the job runs on each clock tick.
  2. The second runs every minute over the course of an hour, verifying that it runs on every multiple of 10.

IMO, scenario 2 is a better representation of the scenario you're looking to validate; however either show the job running more than zero times.

Note that also in my clock file I would recommend saying this job runs every minute. While saying it runs every hour works (as evident in these tests), I think it's less clear to see a job run every 10 minutes when it's said to run hourly.

kevin-j-m commented 6 years ago

Note that with both scenarios I've created tracking down this issue, I cannot reproduce the issue of Clockwork::Test not supporting wildcard times.