[英]How to test jobs which were scheduled (each one min, cron "* * * * *"), but not wait "real" one minute (rufus-scheduler vs virtual time)?
rufus-scheduler
lib allows us to schedule tasks https://github.com/jmettraux/rufus-scheduler rufus-scheduler
lib 允许我们安排任务https://github.com/jmettraux/rufus-scheduler
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
scheduler.cron '* * * * *' do
# do something every minute
end
In fact, when you want to test your app on top of rufus-scheduler
you will need to sleep real 1 min
which is too much for typical tests.事实上,当你想在
rufus-scheduler
之上测试你的应用程序时,你需要real 1 min
睡眠real 1 min
,这对于典型的测试来说太多了。
For example, in Reactor(Java)
they provide StepVerifier.withVirtualTime
in order to avoid long-running tests.`:例如,在
Reactor(Java)
他们提供StepVerifier.withVirtualTime
以避免长时间运行的测试。`:
https://projectreactor.io/docs/core/release/reference/#_manipulating_time https://projectreactor.io/docs/core/release/reference/#_manipulating_time
https://www.baeldung.com/reactive-streams-step-verifier-test-publisher#3-testing-time-based-publishers https://www.baeldung.com/reactive-streams-step-verifier-test-publisher#3-testing-time-based-publishers
RxJava - https://medium.com/@vanniktech/taking-control-of-the-time-when-testing-rxjava-code-91b2e5e88bdf RxJava - https://medium.com/@vanniktech/taking-control-of-the-time-when-testing-rxjava-code-91b2e5e88bdf
Are there any options for time manipulation within tests for rufus-scheduler
or Ruby
itself?在
rufus-scheduler
或Ruby
本身的测试中是否有任何时间操作选项?
Current solution当前解决方案
rufus-scheduler
has type in
, thus for verification of app skeleton I'm using in=0.001s
and sleep 0.4
. rufus-scheduler
有类型in
,因此为了验证应用程序框架,我使用in=0.001s
和sleep 0.4
。
Yes, it takes half-of a second in the test but this is much better than 1 minute.是的,测试需要半秒,但这比 1 分钟要好得多。
Have a look at看一下
or other "time travel" tools.或其他“时间旅行”工具。
I second @spickermann on "only test your own code".我第二次@spickermann 说“只测试你自己的代码”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.