Files
.github
datadog
doc
examples
foreman
src
t
Hydra
Config
Controller
Event
BuildFinished.t
BuildQueued.t
BuildStarted.t
CachedBuildFinished.t
CachedBuildQueued.t
EvalAdded.t
EvalCached.t
EvalFailed.t
EvalStarted.t
StepFinished.t
Helper
Plugin
Schema
View
Event.t
Math.t
PostgresListener.t
TaskDispatcher.t
input-types
jobs
lib
queue-runner
scripts
Makefile.am
api-test.t
build-products.t
evaluate-basic.t
evaluate-dependent-jobsets.t
perlcritic.pl
s3-backup-test.config
s3-backup-test.pl
setup-notifications-jobset.pl
test.pl
.editorconfig
.gitignore
.perlcriticrc
.yath.rc
COPYING
INSTALL
Makefile.am
Procfile
README.md
bootstrap
configure.ac
default.nix
flake.lock
flake.nix
hydra-api.yaml
hydra-module.nix
shell.nix
version.txt
hydra/t/Hydra/Event/EvalStarted.t
Graham Christensen c30f084f32 eval_started event: change interface to traceID\tjobsetID
I was not going to break the interface until I noticed
the current implementation uses the string literal \t.
2022-02-08 09:51:35 -05:00

95 lines
2.6 KiB
Perl

use strict;
use warnings;
use Setup;
use Hydra::Event;
use Hydra::Event::EvalStarted;
use Test2::V0;
use Test2::Tools::Exception;
use Test2::Tools::Mock qw(mock_obj);
my $ctx = test_context();
my $builds = $ctx->makeAndEvaluateJobset(
expression => "basic.nix",
build => 1
);
subtest "Parsing eval_started" => sub {
like(
dies { Hydra::Event::parse_payload("eval_started", "") },
qr/two arguments/,
"empty payload"
);
like(
dies { Hydra::Event::parse_payload("eval_started", "abc123") },
qr/two arguments/,
"one argument"
);
like(
dies { Hydra::Event::parse_payload("eval_started", "abc123\tabc123\tabc123") },
qr/two arguments/,
"three arguments"
);
like(
dies { Hydra::Event::parse_payload("eval_started", "abc123\tabc123") },
qr/should be an integer/,
"not an integer: second argument"
);
is(
Hydra::Event::parse_payload("eval_started", "abc123\t456"),
Hydra::Event::EvalStarted->new("abc123", 456)
);
};
subtest "interested" => sub {
my $event = Hydra::Event::EvalStarted->new(123, []);
subtest "A plugin which does not implement the API" => sub {
my $plugin = {};
my $mock = mock_obj $plugin => ();
is($event->interestedIn($plugin), 0, "The plugin is not interesting.");
};
subtest "A plugin which does implement the API" => sub {
my $plugin = {};
my $mock = mock_obj $plugin => (
add => [
"evalStarted" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my $jobset = $builds->{"empty_dir"}->jobset;
my $event = Hydra::Event::EvalStarted->new("traceID", $jobset->id);
$event->load($ctx->db());
is($event->{"jobset"}->get_column("id"), $jobset->id, "The jobset record matches.");
# Create a fake "plugin" with a evalStarted sub, the sub sets this
# "global" passedTraceID, passedJobset
my $passedTraceID;
my $passedJobset;
my $plugin = {};
my $mock = mock_obj $plugin => (
add => [
"evalStarted" => sub {
my ($self, $traceID, $jobset) = @_;
$passedTraceID = $traceID;
$passedJobset = $jobset;
}
]
);
$event->execute($ctx->db(), $plugin);
is($passedTraceID, "traceID", "The plugin is told what the trace ID was");
is($passedJobset->get_column("id"), $jobset->id, "The plugin's evalStarted hook is called with the right jobset");
};
done_testing;