Work towards having Spectre::Workflow::getJsonStatus return information about

all sites, needed for munging workflow monitoring into wremonitor.pl.
This commit is contained in:
Chris Nehren 2007-11-02 18:08:20 +00:00
parent c7334e2b22
commit 3e2bad5cb4
2 changed files with 100 additions and 6 deletions

85
t/Spectre/Workflow.t Executable file
View file

@ -0,0 +1,85 @@
# vim: syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib", "/data/wre/lib";
use WebGUI::Test;
use WebGUI::Session;
use Spectre::Admin;
use WebGUI::Config;
use WebGUI::Workflow::Cron;
use WebGUI::Workflow::Instance;
use WRE::Config;
use WRE::Modperl;
use WRE::Modproxy;
use WRE::Spectre;
use POE::Component::IKC::ClientLite;
use JSON;
use Config::JSON;
use Data::Dumper;
use Test::More tests => 10; # increment this value for each test you create
$|++;
my $session = WebGUI::Test->session;
my $wreConfig = WRE::Config->new;
my $isModPerlRunning = WRE::Modperl->new ( wreConfig=>$wreConfig)->ping;
my $isModProxyRunning = WRE::Modproxy->new( wreConfig=>$wreConfig)->ping;
my $isSpectreRunning = WRE::Spectre->new ( wreConfig=>$wreConfig)->ping;
my $spectreConfigFile = WebGUI::Test->root . '/etc/spectre.conf';
my $spectreConfig = Config::JSON->new($spectreConfigFile);
my $ip = $spectreConfig->get('ip');
my $port = $spectreConfig->get('port');
# put your tests here
SKIP: {
skip "need modperl, modproxy, and spectre running to test", 10 unless ($isModPerlRunning && $isModProxyRunning && $isSpectreRunning);
# XXX kinda evil kludge to put an activity in the scheduler so that the
# below calls return data; suggestions on a better way to do this welcomed.
my $taskId = 'pbcron0000000000000001'; # hopefully people don't delete daily maintenance
my $task = WebGUI::Workflow::Cron->new($session, $taskId);
# just in case they did...
skip "need daily maintenance task for test", 10 unless defined $task;
my $instance = WebGUI::Workflow::Instance->create($session, {
workflowId => $task->get('workflowId'),
className => $task->get('className'),
methodName => $task->get('methodName'),
parameters => $task->get('parameters'),
priority => $task->get('priority'),
},
);
my $remote = create_ikc_client(
port => $port,
ip => $ip,
name => rand(100000),
timeout => 10
);
my $result = $remote->post_respond('workflow/getJsonStatus');
ok(defined $result, 'can call getJsonStatus');
$remote->disconnect;
undef $remote;
my $structure;
ok($structure = jsonToObj($result), 'workflow/getJsonStatus returns a proper JSON data structure');
diag(Dumper $structure);
cmp_ok(ref $structure, 'eq', 'HASH', 'workflow/getJsonStatus returns a JSON structure parseable into a Perl hashref');
my $sitename = $session->config->get('sitename')->[0];
ok(exists $structure->{$sitename}, "$sitename exists in returned structure");
for my $key(qw/Suspended Waiting Running/) {
ok(exists $structure->{$sitename}{$key}, "$key exists for $sitename");
cmp_ok(ref $structure->{$sitename}{$key}, 'eq', 'HASH', "$key is a hashref in the $sitename hash");
}
}