Skip to content

Commit 39e6839

Browse files
Capture CI worker output to files
1 parent d0ca14d commit 39e6839

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

.github/workflows/php.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,24 @@ jobs:
8282
DB_CONNECTION: mysql
8383
DB_PORT: ${{ job.services.mysql.ports[3306] }}
8484
QUEUE_CONNECTION: redis
85-
WORKFLOW_TEST_STREAM_WORKER_OUTPUT: 1
85+
WORKFLOW_TEST_CAPTURE_WORKER_OUTPUT: 1
8686

8787
- name: Run test suite (PostgreSQL)
8888
run: vendor/bin/phpunit --testdox --debug --testsuite feature
8989
env:
9090
DB_CONNECTION: pgsql
9191
DB_PORT: ${{ job.services.postgres.ports[5432] }}
9292
QUEUE_CONNECTION: redis
93-
WORKFLOW_TEST_STREAM_WORKER_OUTPUT: 1
93+
WORKFLOW_TEST_CAPTURE_WORKER_OUTPUT: 1
9494

9595
- name: Upload laravel.log if tests fail
9696
if: failure()
9797
uses: actions/upload-artifact@v4
9898
with:
9999
name: laravel-log
100-
path: vendor/orchestra/testbench-core/laravel/storage/logs/laravel.log
100+
path: |
101+
vendor/orchestra/testbench-core/laravel/storage/logs/laravel.log
102+
vendor/orchestra/testbench-core/laravel/storage/logs/workflow-test-worker-*.log
101103
102104
- name: Code Coverage
103105
run: |

tests/TestCase.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ public static function setUpBeforeClass(): void
4343

4444
for ($i = 0; $i < self::NUMBER_OF_WORKERS; $i++) {
4545
self::$workers[$i] = new Process(['php', __DIR__ . '/../vendor/bin/testbench', 'queue:work']);
46-
if (! self::shouldStreamWorkerOutput()) {
46+
if (! self::shouldCaptureWorkerOutput()) {
4747
self::$workers[$i]->disableOutput();
4848
self::$workers[$i]->start();
4949
continue;
5050
}
5151

52+
file_put_contents(self::workerLogPath($i), '');
53+
5254
self::$workers[$i]->start(static function (string $type, string $output) use ($i): void {
53-
fwrite(STDERR, '[worker-' . $i . '][' . $type . '] ' . $output);
55+
file_put_contents(self::workerLogPath($i), $output, FILE_APPEND | LOCK_EX);
5456
});
5557
}
5658
}
@@ -102,10 +104,19 @@ protected function getPackageProviders($app)
102104
return [\Workflow\Providers\WorkflowServiceProvider::class];
103105
}
104106

105-
private static function shouldStreamWorkerOutput(): bool
107+
private static function shouldCaptureWorkerOutput(): bool
106108
{
107-
$value = getenv('WORKFLOW_TEST_STREAM_WORKER_OUTPUT') ?: ($_ENV['WORKFLOW_TEST_STREAM_WORKER_OUTPUT'] ?? null);
109+
$value = getenv(
110+
'WORKFLOW_TEST_CAPTURE_WORKER_OUTPUT'
111+
) ?: ($_ENV['WORKFLOW_TEST_CAPTURE_WORKER_OUTPUT'] ?? null);
108112

109113
return in_array($value, ['1', 'true', 'yes', 'on'], true);
110114
}
115+
116+
private static function workerLogPath(int $worker): string
117+
{
118+
return dirname(
119+
__DIR__
120+
) . '/vendor/orchestra/testbench-core/laravel/storage/logs/workflow-test-worker-' . $worker . '.log';
121+
}
111122
}

0 commit comments

Comments
 (0)