From cbdc5b0d67aa39ba60c2691e2dd5c4e6bf30557c Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Tue, 28 Jan 2025 22:14:59 -0300 Subject: [PATCH 1/3] [12.x] feat: MemoryExceeded 0 should mean infinite memory --- src/Illuminate/Queue/Worker.php | 2 +- tests/Queue/QueueWorkerTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 49ad0aa3bce6..e7655c0264a1 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -748,7 +748,7 @@ protected function supportsAsyncSignals() */ public function memoryExceeded($memoryLimit) { - return (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit; + return $memoryLimit && (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit; } /** diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index 33aa4c8dc785..1b79016e4904 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -100,6 +100,18 @@ public function testWorkerStopsWhenMemoryExceeded() $this->events->shouldHaveReceived('dispatch')->with(m::type(JobProcessed::class))->once(); } + public function testWorkerWemoryExceededWhenMemoryIsZero() + { + $worker = new Worker(...$this->workerDependencies()); + $this->assertFalse($worker->memoryExceeded(0)); + } + + public function testWorkerWemoryExceededWhenMemoryGreaterThanZero() + { + $worker = new Worker(...$this->workerDependencies()); + $this->assertTrue($worker->memoryExceeded(1)); + } + public function testJobCanBeFiredBasedOnPriority() { $worker = $this->getWorker('default', [ From f7935f08f284a7de9445a443be9801b2b2c415be Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Tue, 28 Jan 2025 22:34:52 -0300 Subject: [PATCH 2/3] [12.x] feat: MemoryExceeded 0 should mean infinite memory --- src/Illuminate/Queue/Worker.php | 2 +- tests/Queue/QueueWorkerTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index e7655c0264a1..c4ffb227a591 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -748,7 +748,7 @@ protected function supportsAsyncSignals() */ public function memoryExceeded($memoryLimit) { - return $memoryLimit && (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit; + return $memoryLimit > 0 && (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit; } /** diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index 1b79016e4904..f8d337711ad5 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -112,6 +112,12 @@ public function testWorkerWemoryExceededWhenMemoryGreaterThanZero() $this->assertTrue($worker->memoryExceeded(1)); } + public function testWorkerWemoryExceededWhenMemoryIsNegative() + { + $worker = new Worker(...$this->workerDependencies()); + $this->assertFalse($worker->memoryExceeded(-1)); + } + public function testJobCanBeFiredBasedOnPriority() { $worker = $this->getWorker('default', [ From 06c069534f1e22b8635cc7ce4bcbf0fefff1ed64 Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Tue, 28 Jan 2025 22:39:38 -0300 Subject: [PATCH 3/3] [12.x] feat: MemoryExceeded 0 should mean infinite memory --- tests/Queue/QueueWorkerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index f8d337711ad5..6c511807a50c 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -100,19 +100,19 @@ public function testWorkerStopsWhenMemoryExceeded() $this->events->shouldHaveReceived('dispatch')->with(m::type(JobProcessed::class))->once(); } - public function testWorkerWemoryExceededWhenMemoryIsZero() + public function testWorkerMemoryExceededWhenMemoryIsZero() { $worker = new Worker(...$this->workerDependencies()); $this->assertFalse($worker->memoryExceeded(0)); } - public function testWorkerWemoryExceededWhenMemoryGreaterThanZero() + public function testWorkerMemoryExceededWhenMemoryGreaterThanZero() { $worker = new Worker(...$this->workerDependencies()); $this->assertTrue($worker->memoryExceeded(1)); } - public function testWorkerWemoryExceededWhenMemoryIsNegative() + public function testWorkerMemoryExceededWhenMemoryIsNegative() { $worker = new Worker(...$this->workerDependencies()); $this->assertFalse($worker->memoryExceeded(-1));