Skip to content

Commit

Permalink
Add an explicit unit test for the workers exec and delay functions
Browse files Browse the repository at this point in the history
I've wrote this test when checking the worker code for
https://progress.opensuse.org/issues/96710.
  • Loading branch information
Martchus committed Aug 11, 2021
1 parent d967c57 commit fa8f19f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions t/24-worker-overall.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ combined_like { $worker->log_setup_info }
qr/.*http:\/\/localhost:9527,https:\/\/remotehost.*qemu_i386,qemu_x86_64.*Errors occurred.*foo.*bar.*/s,
'setup info with parse errors';

subtest 'delay and exec' => sub {
my $worker_mock = Test::MockModule->new('OpenQA::Worker');
$worker_mock->redefine(init => 42);

my %executed_code_paths;
my %expected_code_paths = map { $_ => 1 } qw(before_delay after_delay another_event);
Mojo::IOLoop->next_tick(
sub {
$executed_code_paths{before_delay} = 1;
note 'before delay';
Mojo::IOLoop->timer(
0 => sub {
$executed_code_paths{another_event} = 1;
note 'another event';
});
$worker->delay(0);
$executed_code_paths{after_delay} = 1;
note 'after delay';
});
is $worker->exec, 42, 'return code passed from init';
is_deeply \%executed_code_paths, \%expected_code_paths, 'all code paths executed'
or diag explain \%executed_code_paths;
};

subtest 'capabilities' => sub {
my $capabilities = $worker->capabilities;

Expand Down

0 comments on commit fa8f19f

Please sign in to comment.