function WorkAllocator::process

Allocates tests to workers.

1 call to WorkAllocator::process()
WorkAllocator::__construct in core/tests/Drupal/TestTools/TestRunner/WorkAllocator.php

File

core/tests/Drupal/TestTools/TestRunner/WorkAllocator.php, line 76

Class

WorkAllocator
Allocates available tests to test workers.

Namespace

Drupal\TestTools\TestRunner

Code

private function process() : void {
  // Separate tests in the '#slow' group from the rest.
  $slowTests = $this->groupedTestClassInfoList['#slow'] ?? [];
  $notSlowTests = [];
  foreach ($this->groupedTestClassInfoList as $group => $tests) {
    if ($group === '#slow') {
      continue;
    }
    $notSlowTests = array_merge($notSlowTests, $tests);
  }
  // Filter slow tests out of the not slow tests and ensure a unique list
  // since tests may appear in more than one group.
  $notSlowTests = array_diff_key($notSlowTests, $slowTests);
  // Sort all tests.
  $this->sortTestsByTypeAndCount($slowTests);
  $this->sortTestsByTypeAndCount($notSlowTests);
  $this->sortedList = array_merge($slowTests, $notSlowTests);
  $this->assignTestsSequence($this->sortedList, 'sorted_sequence');
  // If the tests are not being run in parallel, the sorted list is enough.
  if ($this->totalBins <= 1) {
    $this->allocatedList = $this->sortedList;
    $this->assignTestsSequence($this->allocatedList, 'worker_sequence');
    return;
  }
  // Set up a bin per test runner. Loop over the slow tests and add them to
  // a bin one by one, this distributes the tests evenly across the bins.
  $binnedSlowTests = $this->placeTestsIntoBins($slowTests);
  $slowTestsForJob = $binnedSlowTests[$this->binIndex - 1];
  // And the same for the rest of the tests.
  $binnedOtherTests = $this->placeTestsIntoBins($notSlowTests);
  $otherTestsForJob = $binnedOtherTests[$this->binIndex - 1];
  $this->allocatedList = array_merge($slowTestsForJob, $otherTestsForJob);
  $this->assignTestsSequence($this->allocatedList, 'worker_sequence');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.