#!perl use strict; use warnings; use Test::More tests => 13; use Test::Differences; use FindBin '$Bin'; use lib "$Bin/lib"; use DBICTest; use POE; use Path::Class; my $schema; ok($schema = DBICTest->init_schema, "Got schema"); use_ok('MooseX::JobQueue::Manager::JobSource::DBIxClass'); ok(my $manager = new MooseX::JobQueue::Manager::JobSource::DBIxClass({ job_namespace => ['JobTest'], sleep_interval => 2, config_filename => "", schema => $schema, source => 'JobQueue', }), "Got manager"); $poe_kernel->run_one_timeslice(); ok(exists $manager->job_handlers->{'JobTest::WriteFile'}, "Got expected handler"); my $tmp_dir = dir('t')->subdir(qw/tmp jobqueue/); $tmp_dir->mkpath; my $file1 = $tmp_dir->file('file1.txt'); my $jobs_rs = $schema->resultset('JobQueue'); ok(my $job = $jobs_rs->create({ job_type => "JobTest::WriteFile", args => { filename => "$file1", contents => <<'EOF', Look at me! I'm some text! EOF }, coalesce => "$file1" }), "Job created"); $job->discard_changes; is(ref $job->args, 'HASH', "Job args inflated correctly"); # Create a 2nd coalesced job $jobs_rs->create({ job_type => "JobTest::WriteFile", args => { filename => "$file1", contents => <<'EOF', ------ I should be at the end EOF }, coalesce => "$file1", }); my $failing_job = $jobs_rs->create({ job_type => "JobTest::WriteFile", args => { filename => '/some/path/that/really/really/shouldnt/exist.txt', contents => 'foo' } }); $poe_kernel->call($manager->get_session_id, 'find_jobs'); $job->discard_changes; isnt($job->status, 'available', "Job has been started"); $poe_kernel->run_one_timeslice; is($manager->num_workers, 2, "We have 2 workers"); # Test SIGINT handler works properly. { diag "Testing SIGINT handler"; my $killed = 0; local $SIG{ALRM} = sub { unless ($killed) { $killed = 1; kill 2, $$; } else { ok(0, "SIGINT terminates cleanly"); $poe_kernel->stop; } }; alarm ($manager->sleep_interval * 4); $poe_kernel->run; alarm 0; ok($killed, "SIGINT terminates cleanly"); } my $contents = $file1->slurp; eq_or_diff($contents, <<'EOF', "File got written to"); Look at me! I'm some text! ------ I should be at the end EOF $job->discard_changes; is($job->status, 'done', "Job completed"); $failing_job->discard_changes; is($failing_job->status, 'available', "Failed job is available again"); is(DateTime->compare($failing_job->not_before, DateTime->now), 1, "Failed job has a not_before date in the future"); END { $tmp_dir->rmtree; }