[PECL-CVS] [pecl-networking-gearman] fix-worker-exit-job-retry: address reviews

[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 13:54:06 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T09:54:01-04:00

Commit: https://github.com/php/pecl-networking-gearman/commit/e294d46e2bf4727b987066407e8aa7e5c6065d0e
Raw diff: https://github.com/php/pecl-networking-gearman/commit/e294d46e2bf4727b987066407e8aa7e5c6065d0e.diff

address reviews

Changed paths:
  M  tests/gearman_worker_integration_test_002.phpt


Diff:

diff --git a/tests/gearman_worker_integration_test_002.phpt b/tests/gearman_worker_integration_test_002.phpt
index 9cae246..9b0749f 100644
--- a/tests/gearman_worker_integration_test_002.phpt
+++ b/tests/gearman_worker_integration_test_002.phpt
@@ -13,14 +13,19 @@ $func = 'issue26_' . getmypid() . '_' . time();
 
 /* Submit a background job */
 $client = new GearmanClient();
-$client->addServer($host, $port);
+if ($client->addServer($host, $port) !== true) {
+    die("FAIL: could not add server");
+}
 $handle = $client->doBackground($func, 'test_payload');
 if ($client->returnCode() !== GEARMAN_SUCCESS) {
-    die("Could not submit job");
+    die("FAIL: could not submit job");
 }
 
 /* Worker 1: grabs the job and exit()s without completing it */
 $pid1 = pcntl_fork();
+if ($pid1 === -1) {
+    die("FAIL: could not fork worker 1");
+}
 if ($pid1 === 0) {
     $w = new GearmanWorker();
     $w->addServer($host, $port);
@@ -31,12 +36,18 @@ if ($pid1 === 0) {
     exit(0);
 }
 pcntl_waitpid($pid1, $status1, 0);
+if (!pcntl_wifexited($status1) || pcntl_wexitstatus($status1) !== 1) {
+    die("FAIL: worker 1 did not exit from inside the callback");
+}
 
 /* Brief pause for gearmand to detect the disconnect */
 usleep(500000);
 
 /* Worker 2: should receive the retried job */
 $pid2 = pcntl_fork();
+if ($pid2 === -1) {
+    die("FAIL: could not fork worker 2");
+}
 if ($pid2 === 0) {
     $w = new GearmanWorker();
     $w->addServer($host, $port);
@@ -50,7 +61,9 @@ if ($pid2 === 0) {
 }
 pcntl_waitpid($pid2, $status2, 0);
 
-if (pcntl_wexitstatus($status2) === 0) {
+if (!pcntl_wifexited($status2)) {
+    echo "FAIL: worker 2 did not exit normally" . PHP_EOL;
+} elseif (pcntl_wexitstatus($status2) === 0) {
     echo "PASS" . PHP_EOL;
 } else {
     echo "FAIL: job was not retried" . PHP_EOL;