Fix pod typo (RT #47434)
[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";
bec4be8c 8use Test::More;
9use Storable qw/lock_store lock_retrieve/;
10
11plan tests => 6;
f9d8e3cf 12use Catalyst::Test 'TestApp';
13
14our $STATE = "$FindBin::Bin/lib/TestApp/scheduler.state";
15
16TestApp->schedule(
17 at => '* * * * *',
18 event => '/cron/every_minute',
19 auto_run => 0,
20);
21
bec4be8c 22# hack the last event check to make all events execute immediately
23my $state = { last_check => 0 };
24lock_store $state, $STATE;
f9d8e3cf 25
26# disallow localhost
27TestApp->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
bec4be8c 38$state = lock_retrieve $STATE;
39$state->{last_check} = 0;
40lock_store $state, $STATE;
f9d8e3cf 41
42# allow localhost
43TestApp->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}