Scheduler, more tests, almost feature-complete, todo: YAML
[catagits/Catalyst-Plugin-Scheduler.git] / t / 04schedule.t
index 82c8965..1e34b61 100644 (file)
@@ -6,11 +6,13 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 use Test::More;
+use Storable qw/lock_store lock_retrieve/;
 
 plan tests => 10;
-
 use Catalyst::Test 'TestApp';
 
+our $STATE = "$FindBin::Bin/lib/TestApp/scheduler.state";
+
 TestApp->schedule(
     at    => '* * * * *',
     event => '/cron/every_minute',
@@ -33,7 +35,8 @@ TestApp->schedule(
 );
 
 # hack the last event check to make all events execute immediately
-TestApp->_last_event_check( 0 );
+my $state = { last_check => 0 };
+lock_store $state, $STATE;
 
 # test that all events execute, and that the error test doesn't break the app
 {
@@ -49,13 +52,16 @@ TestApp->_last_event_check( 0 );
 {
     ok( my $res = request('http://localhost/'), 'request ok' );
     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", undef, 'every_minute did not execute, ok' );
+    unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
     is( -e "$FindBin::Bin/lib/TestApp/every_hour.log", undef, 'every_hour did not execute, ok' );
+    unlink "$FindBin::Bin/lib/TestApp/every_hour.log";
 }
 
 # jump back in time by 2 hours, make sure both events run
 {
-    my $last = TestApp->_last_event_check;
-    TestApp->_last_event_check( $last - ( 60 * 120 ) );
+    my $state = lock_retrieve $STATE;
+    $state->{last_check} -= 60 * 120;
+    lock_store $state, $STATE;
     
     ok( my $res = request('http://localhost/'), 'request ok' );
     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", 1, 'every_minute executed ok' );