The idea was grait, but I'm getting problems doing my tests. I'm willing to use Mojolicious as a Mock Server for my classes using the Asynchronous calls. To explain my problem, I did some sample code like:
use Mojo::Base -strict;
use Test::Most;
use Test::Mojo;
use Mojolicious;
my $t = Test::Mojo->new( Mojolicious->new );
$t->app->routes->get('/my_test')->to( 'cb' => sub { shift->render_json( [1] ) } );
my @calls;
my $delay = Mojo::IOLoop->delay( sub { push( @calls, 'finalize' ); Mojo::IOLoop->stop; } );
$delay->begin;
$t->ua->get( '/my_test', sub { push( @calls, 'GET /my_test' ); $delay->end; } );
# many more get calls prepared like before
Mojo::IOLoop->start;
cmp_deeply( \@calls, [ 'GET /my_test', 'finalize' ] );
done_testing;
In this code I see one thing that I don't like. The Mojo::IOLoop->start, but worst then that the Mojo::IOLoop->stop.
Is there a simple way of removing Mojo::IOLoop->stop and substitute Mojo::IOLoop->start by something like:
while ( Mojo::IOLoop->as_something_to_do ) {
Mojo::IOLoop->one_tick
}
Best Regards
Marcos Rebelo