From b5d3498b113a5e3701e8da4d0c37939e14c34466 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Mon, 2 Sep 2013 19:14:27 +0200 Subject: [PATCH] Add tests on process --- ACU/t/process_basis.t | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ACU/t/process_basis.t diff --git a/ACU/t/process_basis.t b/ACU/t/process_basis.t new file mode 100644 index 0000000..b963305 --- /dev/null +++ b/ACU/t/process_basis.t @@ -0,0 +1,47 @@ +use v5.10.1; +use strict; +use warnings; + +use Test::More; + +BEGIN { + diag("Testing Process on perl $]"); + use_ok('Gearman::Worker'); + use_ok('Process'); +} + +use Process; + +cmp_ok($Process::nb_cpus, 'gt', 0, 'Check number of CPU detected'); + +can_ok('Process', 'register'); + +is(Process::check_load(0), '', "Check the load verification"); +is(Process::check_load(100), '1', "Check the load verification"); + +my $gearman_simulation = bless ( { 'handle' => 'H:noyce:167', + 'argref' => \"", + 'func' => 'mon_test' }, + , 'Gearman::Job' ); + +is(Process::do_work(sub { "ok" }, undef, 100, $gearman_simulation), "ok", "Check simple work"); + +is(Process::do_work(sub { $_[0]->{test} }, { "test" => "It works" }, 100, $gearman_simulation), "It works", "Check returning argument"); + +my $GEARMAN_id = "753154abdf"; +my $GEARMAN_auth = "ksajsdfbnsu-skdghf344J"; +$gearman_simulation->{argref} = \('lengthsizecHJpbnQgIjQyIjsKthird'); + +is(Process::do_work(sub { "ok" }, undef, 100, $gearman_simulation), "ok", "Check simple work with more complex XML"); + +is(Process::do_work(sub { $_[1]->{id} }, { "test" => "It works" }, 100, $gearman_simulation), $GEARMAN_id, "Check returning id given in XML"); +is(Process::do_work(sub { $_[1]->{priority} }, { "test" => "It works" }, 100, $gearman_simulation), 10, "Check returning priority given in XML"); +is(Process::do_work(sub { $_[1]->{auth} }, { "test" => "It works" }, 100, $gearman_simulation), $GEARMAN_auth, "Check returning auth given in XML"); + +is(Process::do_work(sub { $_[1]->{param}->{param1} }, { "test" => "It works" }, 100, $gearman_simulation), 'length', "Check returning named parameter"); +is(Process::do_work(sub { $_[1]->{param}->{argument2} }, { "test" => "It works" }, 100, $gearman_simulation), 'size', "Check returning named parameter"); +is(Process::do_work(sub { $_[1]->{param}->{3} }, { "test" => "It works" }, 100, $gearman_simulation), 'third', "Check returning unnamed parameter"); + +is(Process::do_work(sub { $_[1]->{subtree} }, { "test" => "It works" }, 100, $gearman_simulation), undef, "Check there are no subtree"); + +done_testing();