diff --git a/src/Illuminate/Bus/DatabaseBatchRepository.php b/src/Illuminate/Bus/DatabaseBatchRepository.php index de91c880ccea..d5d7e0ed0870 100644 --- a/src/Illuminate/Bus/DatabaseBatchRepository.php +++ b/src/Illuminate/Bus/DatabaseBatchRepository.php @@ -76,6 +76,7 @@ public function get($limit = 50, $before = null) public function find(string $batchId) { $batch = $this->connection->table($this->table) + ->useWritePdo() ->where('id', $batchId) ->first(); diff --git a/tests/Bus/BusBatchTest.php b/tests/Bus/BusBatchTest.php index 4c54f0f62286..efd72cddfb46 100644 --- a/tests/Bus/BusBatchTest.php +++ b/tests/Bus/BusBatchTest.php @@ -15,6 +15,7 @@ use Illuminate\Database\Capsule\Manager as DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\PostgresConnection; +use Illuminate\Database\Query\Builder; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\CallQueuedClosure; use Mockery as m; @@ -393,9 +394,11 @@ public function test_options_serialization_on_postgres() ->onQueue('test-queue'); $connection = m::spy(PostgresConnection::class); + $builder = m::spy(Builder::class); - $connection->shouldReceive('table')->andReturnSelf() - ->shouldReceive('where')->andReturnSelf(); + $connection->shouldReceive('table')->andReturn($builder); + $builder->shouldReceive('useWritePdo')->andReturnSelf(); + $builder->shouldReceive('where')->andReturnSelf(); $repository = new DatabaseBatchRepository( new BatchFactory(m::mock(Factory::class)), $connection, 'job_batches' @@ -403,10 +406,12 @@ public function test_options_serialization_on_postgres() $repository->store($pendingBatch); - $connection->shouldHaveReceived('insert') + $builder->shouldHaveReceived('insert') ->withArgs(function ($argument) use ($pendingBatch) { return unserialize(base64_decode($argument['options'])) === $pendingBatch->options; }); + + $builder->shouldHaveReceived('first'); } /** @@ -418,7 +423,7 @@ public function test_options_unserialize_on_postgres($serialize, $options) $connection = m::spy(PostgresConnection::class); - $connection->shouldReceive('table->where->first') + $connection->shouldReceive('table->useWritePdo->where->first') ->andReturn($m = (object) [ 'id' => '', 'name' => '', diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 2f75cca72218..76d165c1d761 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -585,7 +585,7 @@ public function testRetry() $this->assertEquals(2, $attempts); // Make sure we waited 100ms for the first attempt - $this->assertEqualsWithDelta(0.1, microtime(true) - $startTime, 0.02); + $this->assertEqualsWithDelta(0.1, microtime(true) - $startTime, 0.05); } public function testRetryWithPassingSleepCallback() @@ -608,7 +608,7 @@ public function testRetryWithPassingSleepCallback() $this->assertEquals(3, $attempts); // Make sure we waited 300ms for the first two attempts - $this->assertEqualsWithDelta(0.3, microtime(true) - $startTime, 0.02); + $this->assertEqualsWithDelta(0.3, microtime(true) - $startTime, 0.05); } public function testRetryWithPassingWhenCallback() @@ -629,7 +629,7 @@ public function testRetryWithPassingWhenCallback() $this->assertEquals(2, $attempts); // Make sure we waited 100ms for the first attempt - $this->assertEqualsWithDelta(0.1, microtime(true) - $startTime, 0.02); + $this->assertEqualsWithDelta(0.1, microtime(true) - $startTime, 0.05); } public function testRetryWithFailingWhenCallback() @@ -661,7 +661,7 @@ public function testRetryWithBackoff() // Make sure we made four attempts $this->assertEquals(4, $attempts); - $this->assertEqualsWithDelta(0.05 + 0.1 + 0.2, microtime(true) - $startTime, 0.02); + $this->assertEqualsWithDelta(0.05 + 0.1 + 0.2, microtime(true) - $startTime, 0.05); } public function testTransform()