Tasks: only execute the event if the plugin is interested in it

This commit is contained in:
Graham Christensen
2021-12-20 13:27:59 -05:00
parent 633fc36d6a
commit a14501c616
12 changed files with 150 additions and 21 deletions

View File

@ -54,6 +54,28 @@ my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir});
ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0");
is(nrQueuedBuildsForJobset($jobset), 3, "Evaluating jobs/basic.nix should result in 3 builds");
subtest "interested" => sub {
my $event = Hydra::Event::BuildFinished->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 => [
"buildFinished" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my ($build, $dependent_a, $dependent_b) = $db->resultset('Builds')->search(
{ },

View File

@ -39,6 +39,28 @@ subtest "Parsing build_queued" => sub {
);
};
subtest "interested" => sub {
my $event = Hydra::Event::BuildQueued->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 => [
"buildQueued" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my $build = $builds->{"empty_dir"};

View File

@ -45,6 +45,28 @@ subtest "Parsing build_started" => sub {
);
};
subtest "interested" => sub {
my $event = Hydra::Event::BuildStarted->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 => [
"buildStarted" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my $build = $db->resultset('Builds')->search(
{ },

View File

@ -64,6 +64,28 @@ subtest "Parsing step_finished" => sub {
);
};
subtest "interested" => sub {
my $event = Hydra::Event::StepFinished->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 => [
"stepFinished" => sub {}
]
);
is($event->interestedIn($plugin), 1, "The plugin is interesting.");
};
};
subtest "load" => sub {
my $step = $db->resultset('BuildSteps')->search(