forkframework.t 1.73 KB
Newer Older
1
#!/usr/bin/perl
Mike Hibler's avatar
Mike Hibler committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2009 University of Utah and the Flux Group.
# All rights reserved.
#
7 8
use SemiModern::Perl;
use TestBed::ForkFramework;
9 10
use TestBed::ParallelRunner::Executor;
use RPC::XML;
11 12
use Data::Dumper;
use Test::Exception;
Kevin Tew's avatar
Kevin Tew committed
13
use Test::More tests => 4;
14

Kevin Tew's avatar
Kevin Tew committed
15 16 17 18
my $date_id_sub = sub { my $d = `date`; chomp($d); $_[0] . " $d "  . $$; };

my $results = TestBed::ForkFramework::ForEach::max_work(2, $date_id_sub, ['K1', 'K2', 'K3', 'K4'] );
ok($results->has_errors == 0 && @{ $results->successes } == 4, 'ForkFramework::ForEach::max_work');
19
#say Dumper($results);
20

Kevin Tew's avatar
Kevin Tew committed
21 22
$results = TestBed::ForkFramework::WeightedScheduler::work(4, $date_id_sub, [['K1', 1], ['K2', 1], ['K3', 2], ['K4', 3] ] );
ok($results->has_errors == 0 && @{ $results->successes } == 4, 'ForkFramework::WeightedScheduler::work');
23
#say Dumper($results);
Kevin Tew's avatar
Kevin Tew committed
24

Kevin Tew's avatar
Kevin Tew committed
25
$results = TestBed::ForkFramework::WeightedScheduler::work(1, 
26 27
  sub { die TestBed::ParallelRunner::Executor::SwapinError->new( 
    original => RPC::XML::struct->new( { value => { cause => 'temp' } })); },
Kevin Tew's avatar
Kevin Tew committed
28 29 30 31 32 33 34 35 36 37 38 39
  [[ TestBed::ParallelRunner::Executor->buildt(test_count => 1, retry => 1), 1]]
);

ok($results->has_errors == 1 && @{ $results->errors } == 1, 'ForkFramework::WeightedScheduler::work, retry');
#say Dumper($results);

my $launchtime = time;
$results = TestBed::ForkFramework::WeightedScheduler::work(4, 
  sub { 
    die TestBed::ParallelRunner::Executor::SwapinError->new( 
    original => RPC::XML::struct->new( { value => { cause => 'temp' } })) if (time - $launchtime < 6); 1;},
  [[ TestBed::ParallelRunner::Executor->buildt(test_count => 1, backoff => "2:10:0"), 1]]
40 41
);

Kevin Tew's avatar
Kevin Tew committed
42
ok($results->has_errors == 0 && @{ $results->successes } == 1, 'ForkFramework::WeightedScheduler::work, backoff');
43
#say Dumper($results);