From be531c6c5719c0ac4c130bd40eaf4c3af93e71ee Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Mon, 7 Feb 2022 14:59:19 -0500 Subject: [PATCH] notifications.t: create a helper to parse the actual messages from the evaluator using the Event code --- t/scripts/hydra-eval-jobset/notifications.t | 30 +++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/t/scripts/hydra-eval-jobset/notifications.t b/t/scripts/hydra-eval-jobset/notifications.t index 3e914bb0..77cec71b 100644 --- a/t/scripts/hydra-eval-jobset/notifications.t +++ b/t/scripts/hydra-eval-jobset/notifications.t @@ -5,6 +5,24 @@ use Setup; use Test2::V0; use File::Copy; use Hydra::PostgresListener; +use Hydra::Event; + +# expectEvent(Hydra::PostgresLister, name of the channel to expect, a sub which gets the parsed event) +sub expectEvent { + my ($listener, $expectedChannel, $then) = @_; + my $message = $listener->block_for_messages(0)->(); + + my $channel = $message->{"channel"}; + + if ($channel eq $expectedChannel) { + my $event = Hydra::Event->new_event($message->{"channel"}, $message->{"payload"}); + local $_ = $event->{event}; + $then->(); + } else { + is($expectedChannel, $channel, "Expecting a message on channel $channel"); + } +} + my $ctx = test_context( hydra_config => q| @@ -38,15 +56,11 @@ my $builds = $ctx->makeAndEvaluateJobset( ); my $jobset = $builds->{"stable-job-queued"}->jobset; -my $traceID; - subtest "on the initial evaluation" => sub { - my $startedMsg = $listener->block_for_messages(0)->(); - is($startedMsg->{"channel"}, "eval_started", "every eval starts with a notification"); - - my ($traceID, $jobsetID) = split("\t", $startedMsg->{"payload"}); - isnt($traceID, "", "we got a trace id"); - is($jobsetID, $jobset->get_column('id'), "the jobset ID matches"); + expectEvent($listener, "eval_started", sub { + isnt($_->{"trace_id"}, "", "We got a trace ID"); + is($_->{"jobset_id"}, $jobset->get_column('id'), "the jobset ID matches"); + }); is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 1/4 builds being queued"); is($listener->block_for_messages(0)->()->{"channel"}, "build_queued", "expect 2/4 builds being queued");