Beekeeper

 view release on metacpan or  search on metacpan

t/lib/Tests/Recursion.pm  view on Meta::CPAN

    $resp = $cli->call_remote(
        method  => 'test.fib2',
        params  => 2,
    );

    is( $resp->result, 1, "fib(2)");

    $resp = $cli->call_remote(
        method  => 'test.fib3',
        params  => 2,
    );

    is( $resp->result, 1, "fib(2)");

    $resp = $cli->call_remote(
        method  => 'test.fib4',
        params  => 2,
    );

    is( $resp->result, 1, "fib(2)");
}

sub test_03_recursion : Test(21) {
    my $self = shift;

    ## This test shows how effective is the broker doing load balance

    if ($self->automated_testing) {
        return "This test does not run reliably on constrained platforms";
    }

    my $running = $self->start_workers('Tests::Service::Worker', worker_count => 8);
    is( $running, 8, "Spawned 8 additional workers");

    my $cli = Beekeeper::Client->instance;

    my @fib = (0,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144);

    #TODO: 11 workers should handle up to fib1(10) with proper load balance
    for (my $i = 3; $i <= 4; $i++) {

        my $resp = $cli->call_remote(
            method  => 'test.fib1',
            params  => $i,
        );

        is( $resp->result, $fib[$i], "fib($i)");
    }

    #TODO: 11 workers should handle up to fib2(5) with proper load balance
    for (my $i = 3; $i <= 4; $i++) {

        my $resp = $cli->call_remote(
            method  => 'test.fib2',
            params  => $i,
        );

        is( $resp->result, $fib[$i], "fib($i)");
    }

    # Asynchronous workers are only limited by available memory
    for (my $i = 3; $i <= 10; $i++) {

        my $resp = $cli->call_remote(
            method  => 'test.fib3',
            params  => $i,
        );

        is( $resp->result, $fib[$i], "fib($i)");
    }

    # Asynchronous workers are only limited by available memory
    for (my $i = 3; $i <= 10; $i++) {

        my $resp = $cli->call_remote(
            method  => 'test.fib4',
            params  => $i,
        );

        is( $resp->result, $fib[$i], "fib($i)");
    }
}

1;



( run in 0.569 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )