eval_cached event: change interface to traceID\tjobsetID\tevaluationID

I was not going to break the interface until I noticed
the current implementation uses the string literal \t.
This commit is contained in:
Graham Christensen
2022-02-07 16:13:26 -05:00
parent be531c6c57
commit 2597fa8c11
8 changed files with 206 additions and 5 deletions

112
t/Hydra/Event/EvalCached.t Normal file
View File

@ -0,0 +1,112 @@
use strict;
use warnings;
use Setup;
use Hydra::Event;
use Hydra::Event::EvalCached;
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_cached" => sub {
like(
dies { Hydra::Event::parse_payload("eval_cached", "") },
qr/three arguments/,
"empty payload"
);
like(
dies { Hydra::Event::parse_payload("eval_cached", "abc123") },
qr/three arguments/,
"one argument"
);
like(
dies { Hydra::Event::parse_payload("eval_cached", "abc123\tabc123") },
qr/three arguments/,
"two arguments"
);
like(
dies { Hydra::Event::parse_payload("eval_cached", "abc123\tabc123\tabc123\tabc123") },
qr/three arguments/,
"four arguments"
);
like(
dies { Hydra::Event::parse_payload("eval_cached", "abc123\tabc123\t123") },
qr/should be an integer/,
"not an integer: second position"
);
like(
dies { Hydra::Event::parse_payload("eval_cached", "abc123\t123\tabc123") },
qr/should be an integer/,
"not an integer: third position"
);
is(
Hydra::Event::parse_payload("eval_cached", "abc123\t123\t456"),
Hydra::Event::EvalCached->new("abc123", 123, 456)
);
};
subtest "interested" => sub {
my $event = Hydra::Event::EvalCached->new("abc123", 123, 456);
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 => [
"evalCached" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my $jobset = $builds->{"empty_dir"}->jobset;
my $evaluation = $builds->{"empty_dir"}->jobsetevals->first();
my $event = Hydra::Event::EvalCached->new("traceID", $jobset->id, $evaluation->id);
$event->load($ctx->db());
is($event->{"trace_id"}, "traceID", "The Trace ID matches");
is($event->{"jobset_id"}, $jobset->id, "The Jobset ID matches");
is($event->{"evaluation_id"}, $evaluation->id, "The Evaluation ID matches");
# Create a fake "plugin" with a evalCached sub, the sub sets these
# "globals"
my $passedTraceID;
my $passedJobset;
my $passedEvaluation;
my $plugin = {};
my $mock = mock_obj $plugin => (
add => [
"evalCached" => sub {
my ($self, $traceID, $jobset, $evaluation) = @_;
$passedTraceID = $traceID;
$passedJobset = $jobset;
$passedEvaluation = $evaluation;
}
]
);
$event->execute($ctx->db(), $plugin);
is($passedTraceID, "traceID", "We get the expected trace ID");
is($passedJobset->id, $jobset->id, "The correct jobset is passed");
is($passedEvaluation->id, $evaluation->id, "The correct evaluation is passed");
};
done_testing;

View File

@ -55,6 +55,7 @@ my $builds = $ctx->makeAndEvaluateJobset(
build => 0
);
my $jobset = $builds->{"stable-job-queued"}->jobset;
my $evaluation = $builds->{"stable-job-queued"}->jobsetevals->first();
subtest "on the initial evaluation" => sub {
expectEvent($listener, "eval_started", sub {
@ -72,9 +73,21 @@ subtest "on the initial evaluation" => sub {
};
subtest "on a subsequent, totally cached / unchanged evaluation" => sub {
ok(evalSucceeds($builds->{"variable-job"}->jobset), "evaluating for the second time");
is($listener->block_for_messages(0)->()->{"channel"}, "eval_started", "an evaluation has started");
is($listener->block_for_messages(0)->()->{"channel"}, "eval_cached", "the evaluation finished and nothing changed");
ok(evalSucceeds($jobset), "evaluating for the second time");
my $traceID;
expectEvent($listener, "eval_started", sub {
isnt($_->{"trace_id"}, "", "We got a trace ID");
$traceID = $_->{"trace_id"};
is($_->{"jobset_id"}, $jobset->get_column('id'), "the jobset ID matches");
});
expectEvent($listener, "eval_cached", sub {
is($_->{"trace_id"}, $traceID, "Trace ID matches");
is($_->{"jobset_id"}, $jobset->get_column('id'), "the jobset ID matches");
is($_->{"evaluation_id"}, $evaluation->get_column('id'), "the evaluation ID matches");
});
is($listener->block_for_messages(0)->(), undef, "there are no more messages from the evaluator");
};