You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In tests, especially those dealing with deadlines, it would be extremely helpful to test that events are firing when they're supposed to.
An example is having a scheduled queue with jobs running at deadlines, and the queue uses a ClockStrike under the hood to run every minute and check for jobs that have deadlines that passed.
Here's a snippet of what such a use case may have as a unit test with today's API
describe("executing jobs"){it("runs jobs after deadline"){letqueue=DataSyncQueue(client: apolloClient, clock: fastClock)await queue.modifyChimeTime(.seconds(1))letjobA=MockJob(priority:.every(1))letjobB=MockAJob(priority:.every(2))letjobC=MockBJob(priority:.every(5))await queue.addJob(jobA)await queue.addJob(jobB)await queue.addJob(jobC)await queue.startSync()tryawaitClocks.system.sleep(for:1)
// because of the scaled nature, we don't always get exactly 10 clock strikes per real world second
// so we expect it to be ran at least a certain amount of times, + 1 to account for a "rounding up" timing error
expect(jobA.timesJobRun).to(beWithin(8...10)) // for this one, we might only get 8 ticks in a second
expect(jobB.timesJobRun).to(beWithin(4...5))expect(jobC.timesJobRun).to(beWithin(1...2))}
Request
The reliability of this test could be vastly improved if there was a ManualClock that allowed us to set now as a fixed point in time, and then only when we tell it to, it increments the current time and does any ClockStrikes as necessary.
The text was updated successfully, but these errors were encountered:
Motivation
In tests, especially those dealing with deadlines, it would be extremely helpful to test that events are firing when they're supposed to.
An example is having a scheduled queue with jobs running at deadlines, and the queue uses a
ClockStrike
under the hood to run every minute and check for jobs that have deadlines that passed.Here's a snippet of what such a use case may have as a unit test with today's API
Request
The reliability of this test could be vastly improved if there was a
ManualClock
that allowed us to setnow
as a fixed point in time, and then only when we tell it to, it increments the current time and does anyClockStrikes
as necessary.The text was updated successfully, but these errors were encountered: