class WorkAllocatorTest

Unit tests for WorkAllocator.

Attributes

#[CoversClass(WorkAllocator::class)] #[Group('Test')]

Hierarchy

Expanded class hierarchy of WorkAllocatorTest

File

core/tests/Drupal/Tests/Core/Test/WorkAllocatorTest.php, line 16

Namespace

Drupal\Tests\Core\Test
View source
class WorkAllocatorTest extends UnitTestCase {
  
  /**
   * Tests sorting and allocation of tests.
   */
  public function testAllocator(int $totalBins, int $binIndex, array $groupedTestClassInfoList, array $expected) : void {
    $allocator = new WorkAllocator($groupedTestClassInfoList, $totalBins, $binIndex);
    $this->assertEquals($expected, $allocator->getAllocatedList());
  }
  
  /**
   * Data for ::testAllocator.
   */
  public static function allocatorProvider() : \Generator {
    $path = __DIR__ . '/../../../../fixtures/test_runner/work_allocator';
    yield 'with slow test, single bin' => [
      1,
      1,
      json_decode(file_get_contents($path . '/simple_in.json'), TRUE),
      json_decode(file_get_contents($path . '/simple_out.json'), TRUE),
    ];
    yield 'with slow test, 2 bins, bin #1' => [
      2,
      1,
      json_decode(file_get_contents($path . '/simple_in.json'), TRUE),
      json_decode(file_get_contents($path . '/simple_one_of_two_out.json'), TRUE),
    ];
    // This is an edge case. Since we have 1 #slow test class and one other
    // test class not #slow, both classes get allocated to bin #1, and bin #2
    // remains empty, because the current algorithm allocates first all #slow
    // then all normal starting again. Does not happen in practice.
    yield 'with slow test, 2 bins, bin #2' => [
      2,
      2,
      json_decode(file_get_contents($path . '/simple_in.json'), TRUE),
      [],
    ];
    yield 'with slow test, 8 bins, bin #2' => [
      8,
      2,
      json_decode(file_get_contents($path . '/complex_in.json'), TRUE),
      json_decode(file_get_contents($path . '/complex_two_of_eight_out.json'), TRUE),
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
DrupalTestCaseTrait::$root protected property The Drupal root directory.
DrupalTestCaseTrait::checkErrorHandlerOnTearDown public function Checks the test error handler after test execution. 1
DrupalTestCaseTrait::getDrupalRoot protected static function Returns the Drupal root directory. 1
DrupalTestCaseTrait::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 357
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.
WorkAllocatorTest::allocatorProvider public static function Data for ::testAllocator.
WorkAllocatorTest::testAllocator public function Tests sorting and allocation of tests.

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