Changes:
[catagits/Catalyst-Plugin-Scheduler.git] / t / 05auto_run.t
CommitLineData
f9d8e3cf 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
ba2735b6 8use Test::More tests => 6;
f9d8e3cf 9use Catalyst::Test 'TestApp';
10
11our $STATE = "$FindBin::Bin/lib/TestApp/scheduler.state";
ba2735b6 12our $BASE = 'Catalyst::Plugin::Scheduler::Base';
13
14# hack the last event check to make all events execute immediately
15$BASE->_last_check_time( 0 );
f9d8e3cf 16
17TestApp->schedule(
18 at => '* * * * *',
19 event => '/cron/every_minute',
20 auto_run => 0,
21);
22
f9d8e3cf 23
24# disallow localhost
25TestApp->config->{scheduler}->{hosts_allow} = '1.2.3.4';
26
27# test that the event does not execute
28{
29 ok( my $res = request('http://localhost/'), 'request ok' );
30 is( $res->content, 'default', 'response ok' );
31 is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", undef, 'every_minute did not execute, ok' );
32 unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
33}
34
35# hack the last event check to make all events execute immediately
ba2735b6 36$BASE->_last_check_time( 0 );
f9d8e3cf 37
38# allow localhost
39TestApp->config->{scheduler}->{hosts_allow} = [ '1.2.3.4', '127.0.0.1' ];
40
41# test that the event does execute
42{
43 ok( my $res = request('http://localhost/'), 'request ok' );
44 is( $res->content, 'default', 'response ok' );
45 is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", 1, 'every_minute executed ok' );
46 unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
47}