App-Prove-Plugin-Elasticsearch

 view release on metacpan or  search on metacpan

bin/testd  view on Meta::CPAN

        platforms     => {},
        cur_platforms => {},
        cur_version   => &{\&{$versioner . "::get_version"}}
          ("$ENV{PWD}/t/bogus.t"),
    );
    foreach my $p (@provisioners) {
        $provision_matrix{version} = $p
          if &{\&{$p . "::can_switch_version"}}($versioner);
        $provision_matrix{platforms}->{$p} = [];
        my $platform;
        ($platform, $platforms) = &{\&{$p . "::pick_platform"}}(@$platforms);
        push(
            @{$provision_matrix{platforms}->{$p}},
            &{\&{$p . "::get_available_provision_targets"}}($platform)
        ) if $platform;    #optimization
        $provision_matrix{cur_platforms}{$p} = $platform;
    }
    $provision_matrix{unsatisfiable_platforms} = $platforms;

    #Figure out what needs doing
    my @satiable_plans = $queue->list_queues(%provision_matrix);

    #Pick one and return it.  I'm deliberately not re-queuing, as that should be taken care of already, and would result in duplicate work in distributed configurations.
    return (shift @satiable_plans, \%provision_matrix);
}

sub _provision {
    my ($candidate, $provision_matrix) = @_;

    #First, let's provision everything we can to match the provided candidate.
    foreach my $platformer (keys(%{$provision_matrix->{platforms}})) {
        my ($platform_to_provision) =
          &{\&{$platformer . "::pick_platform"}}(@{$candidate->{platforms}});
        next unless $platform_to_provision;
        next
          if $platform_to_provision eq
          $provision_matrix->{cur_platforms}->{$platformer};
        print "Provisioning system to $platform_to_provision...\n";
        &{\&{$platformer . "::provision"}}($platform_to_provision);
    }

    #Finally, see if we need to change the version of our software.
    if ($provision_matrix->{version}) {
        if ($candidate->{version} ne $provision_matrix->{cur_version}) {
            print "Provisioning SUT version to $candidate->{version}...\n";
            &{\&{$provision_matrix->{version} . "::switch_version_to"}}
              ($candidate->{version});
        }
    }
    return $candidate;
}

sub worker {
    my ($conf, $worker_state, $jobspec, $q) = @_;
    $worker_state->{MCE->wid()} = 1;
    my $msg = "testd - worker " . MCE->wid() . ":";
    $0 = "$msg starting up";

    while (1) {

        #check if every job is not busy, and if so, return so we can re-provision.
        return 1 unless sum(values(%$worker_state));

        $worker_state->{MCE->wid()} = 1;
        $0 = "$msg looking for jobs";
        my @jobs = $q->get_jobs($jobspec);
        MCE->say("Found " . scalar(@jobs) . " jobs for worker " . MCE->wid());
        if (!@jobs) {
            $worker_state->{MCE->wid()} = 0;
            $0 = "$msg waiting for jobs";
            sleep $interval;
            next;
        }
        $0 = "$msg running tests";
        my $runner = App::Prove::Elasticsearch::Utils::require_runner($conf);
        &{\&{$runner . "::run"}}($conf, @jobs);
    }
}

sub daemonify {
    my ($test_only) = @_
      ; # Flag for unit tests. Unfortunately there's not much other way I can safely test this in a unit test (that I can figure out anyways).
    $test_only //= 0;

    my $pid;
    unless ($test_only) {    # uncoverable branch true
        $pid = fork;
        exit 0 if $pid;
        exit 1 if !defined($pid);
        setsid();
        $pid = fork;
        exit 0 if $pid;
        exit 1 if not defined $pid;
        chdir '/' or die $!;
        umask 0;
        $pid = $$;
    }
    return $pid;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

testd - watch for tests needing running and run them

=head1 VERSION

version 0.001

=head1 USAGE

testd

Requires that you have a configured autodiscover value in your ~/elastest.conf.



( run in 0.603 second using v1.01-cache-2.11-cpan-39bf76dae61 )