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