Skip to content

Commit

Permalink
Merge pull request #5955 from Martchus/coverage-test-1
Browse files Browse the repository at this point in the history
Avoid problem with coverage report
  • Loading branch information
mergify[bot] authored Sep 30, 2024
2 parents d5e5ab9 + a86bb89 commit 04d6aad
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions t/05-scheduler-full.t
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,17 @@ sub wait_for_worker {
for (0 .. 40) {
my $worker = $schema->resultset('Workers')->find($id);
return undef if defined $worker && !$worker->dead;
sleep .5;
sleep .5; # uncoverable statement
}
note "No worker with ID $id active"; # uncoverable statement
}

sub scheduler_step { OpenQA::Scheduler::Model::Jobs->singleton->schedule() } # uncoverable statement

my $job_model = OpenQA::Scheduler::Model::Jobs->singleton;
my $worker_settings = [$api_key, $api_secret, "http://localhost:$mojoport"];

subtest 'Scheduler worker job allocation' => sub {
note 'try to allocate to previous worker (supposed to fail)';
my $allocated = scheduler_step();
my $allocated = $job_model->schedule;
is @$allocated, 0, 'no jobs allocated for no active workers';

note 'starting two workers';
Expand All @@ -112,7 +111,7 @@ subtest 'Scheduler worker job allocation' => sub {
wait_for_worker($schema, 4);

note 'assigning one job to each worker';
$allocated = scheduler_step();
$allocated = $job_model->schedule;
my $job_id1 = $allocated->[0]->{job};
my $job_id2 = $allocated->[1]->{job};
my $wr_id1 = $allocated->[0]->{worker};
Expand All @@ -121,7 +120,7 @@ subtest 'Scheduler worker job allocation' => sub {
my $different_jobs = isnt($job_id1, $job_id2, 'each of the two jobs allocated to one of the workers');
diag explain $allocated unless $different_workers && $different_jobs;

$allocated = scheduler_step();
$allocated = $job_model->schedule;
is @$allocated, 0, 'no more jobs need to be allocated';

stop_workers;
Expand All @@ -138,13 +137,13 @@ subtest 're-scheduling and incompletion of jobs when worker rejects jobs or goes
shift(@latest)->auto_duplicate();

# try to allocate to previous worker and fail!
my $allocated = scheduler_step();
my $allocated = $job_model->schedule;
is @$allocated, 0, 'no jobs can be allocated to previous workers';

# simulate a worker in broken state; it will register itself but declare itself as broken
@workers = broken_worker(@$worker_settings, 3, 'out of order');
wait_for_worker($schema, 5);
$allocated = scheduler_step();
$allocated = $job_model->schedule;
is @$allocated, 0, 'scheduler does not consider broken worker for allocating job';
stop_workers;
dead_workers($schema);
Expand All @@ -157,7 +156,7 @@ subtest 're-scheduling and incompletion of jobs when worker rejects jobs or goes
# the loop is needed as the scheduler sometimes needs a second
# cycle before the worker is seen as unusable
for (1 .. 2) {
$allocated = scheduler_step();
$allocated = $job_model->schedule;
last if $allocated && @$allocated >= 1;
note "scheduler could not yet assign to rejective worker, try: $_"; # uncoverable statement
}
Expand Down Expand Up @@ -187,7 +186,7 @@ subtest 're-scheduling and incompletion of jobs when worker rejects jobs or goes
@workers = unstable_worker(@$worker_settings, 3, -1);
wait_for_worker($schema, 5);
for (1 .. 2) {
$allocated = scheduler_step();
$allocated = $job_model->schedule;
last if $allocated && @$allocated >= 1;
note "scheduler could not yet assign to broken worker, try: $_"; # uncoverable statement
}
Expand Down Expand Up @@ -223,7 +222,7 @@ subtest 'Simulation of heavy unstable load' => sub {
my $i = 2;
wait_for_worker($schema, ++$i) for 1 .. $nr;

my $allocated = scheduler_step(); # Will try to allocate to previous worker and fail!
my $allocated = $job_model->schedule; # Will try to allocate to previous worker and fail!
is @$allocated, 10, 'Allocated maximum number of jobs that could have been allocated' or die;
my %jobs;
my %w;
Expand All @@ -249,7 +248,7 @@ subtest 'Simulation of heavy unstable load' => sub {
$i = 5;
wait_for_worker($schema, ++$i) for 0 .. 12;

$allocated = scheduler_step(); # Will try to allocate to previous worker and fail!
$allocated = $job_model->schedule; # Will try to allocate to previous worker and fail!
is @$allocated, 0, 'All failed allocation on second step - workers were killed';
for my $dup (@duplicated) {
for (0 .. 2000) {
Expand Down

0 comments on commit 04d6aad

Please sign in to comment.