# 1
# start only in production mode. Bad but quick
if ($app->mode eq 'production') {
Mojo::IOLoop->recurring(10 => sub {...});
}
This doesn't look like a dirty testing hack, this is exactly a dirty
testing hack... Singletons are untestable
# 2
# This is much better and more perlish
package App;
sub start_foo {
Mojo::IOLoop->recurring(10 => sub {...});
}
package main;
local *App::start_foo = sub {'mock'};
#.... you test here
Hi, I have my webapp where I have a Mojo::IOLoop->recurring(10 => sub
{ # relaoding from db }) running (inside the app in the background,
not really handling any web request) that reloads some configuration
from the database.
When I want to do testing, I want to insert a testing entry in the
database, and then run some testing code. But it does not work if I do,
#
# insert some test artifact to the database
#
Mojo::IOLoop->timer(15 => sub { print "done waiting for database
reload" });
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
#
# some cleanup code
#
done_testing;
I saw that the whole thing just keep on going without running the
cleanup code (the reloading keeps running). So I think the
Mojo::IOLoop is the singleton and since the recurring timer is still
active, it just keeps on running. What is the proper way to make it
working? Any ideas are appreciated.
Daniel.
--
You received this message because you are subscribed to the Google
Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.