Skip to content

Commit

Permalink
Merge pull request #136 from DonCallisto/queue_ordering
Browse files Browse the repository at this point in the history
Issue #135 fix
  • Loading branch information
DonCallisto authored Oct 5, 2019
2 parents 1404bd9 + 03079e8 commit a10d96a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Process/ProcessesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function assertNProcessRunning(QueueInterface &$queue, Processes &$proces

$currentProcessNumber = $this->getCurrentProcessCounter();
$this->incrementForThisChannel($currentChannel);
$process = $this->processFactory->createAProcess($queue->pop(), $currentChannel, $currentProcessNumber, $this->isFirstForThisChannel($currentChannel));
$process = $this->processFactory->createAProcess($queue->shift(), $currentChannel, $currentProcessNumber, $this->isFirstForThisChannel($currentChannel));
$processes->add($currentChannel, $process);
$processes->start($currentChannel);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Queue/Infrastructure/InMemoryQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function pop()
return array_pop($this->queue);
}

public function shift()
{
return array_shift($this->queue);
}

public function push(TestsQueue $testSuite)
{
$this->queue = array_merge($this->queue, $testSuite->toArray());
Expand Down
7 changes: 7 additions & 0 deletions src/Queue/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ interface QueueInterface
{
/**
* @return TestSuite
*
* @deprecated Will be removed in v2
*/
public function pop();

/**
* @return TestSuite
*/
public function shift();

/**
* Push a collections of tests.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Process/ProcessesManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function shouldCreateProcessesWithoutBeforeProcessExecutingFactoryWithThe
->method('isEmpty')
->willReturn(false);
$queue->expects($this->once())
->method('pop')
->method('shift')
->willReturn(new TestSuite('path'));

$processes = $this->getMockBuilder('Liuggio\Fastest\Process\Processes')
Expand Down Expand Up @@ -73,7 +73,7 @@ public function shouldCreate6ProcessesGivingThemTheCorrectEnvParameters()
->method('isEmpty')
->willReturn(false);
$queue->expects($this->exactly(6))
->method('pop')
->method('shift')
->willReturn(new TestSuite('path'));

$processes = $this->getMockBuilder('Liuggio\Fastest\Process\Processes')
Expand Down
13 changes: 13 additions & 0 deletions tests/Queue/Infrastructure/InMemoryQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ public function shouldPopAndPushASuite()
$this->assertEquals('a', $queue->pop());
$this->assertTrue($queue->isEmpty());
}

/**
* @test
*/
public function shouldPopAndShiftASuite()
{
$queue = new InMemoryQueue();
$tests = new TestsQueue(['a', 'b']);
$queue->push($tests);
$this->assertEquals('a', $queue->shift());
$this->assertEquals('b', $queue->shift());
$this->assertTrue($queue->isEmpty());
}
}

0 comments on commit a10d96a

Please sign in to comment.