Skip to content

Commit d0ca14d

Browse files
Stream feature worker output in CI
1 parent 3456f71 commit d0ca14d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

.github/workflows/php.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ jobs:
8282
DB_CONNECTION: mysql
8383
DB_PORT: ${{ job.services.mysql.ports[3306] }}
8484
QUEUE_CONNECTION: redis
85+
WORKFLOW_TEST_STREAM_WORKER_OUTPUT: 1
8586

8687
- name: Run test suite (PostgreSQL)
8788
run: vendor/bin/phpunit --testdox --debug --testsuite feature
8889
env:
8990
DB_CONNECTION: pgsql
9091
DB_PORT: ${{ job.services.postgres.ports[5432] }}
9192
QUEUE_CONNECTION: redis
93+
WORKFLOW_TEST_STREAM_WORKER_OUTPUT: 1
9294

9395
- name: Upload laravel.log if tests fail
9496
if: failure()

tests/TestCase.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ 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-
self::$workers[$i]->disableOutput();
47-
self::$workers[$i]->start();
46+
if (! self::shouldStreamWorkerOutput()) {
47+
self::$workers[$i]->disableOutput();
48+
self::$workers[$i]->start();
49+
continue;
50+
}
51+
52+
self::$workers[$i]->start(static function (string $type, string $output) use ($i): void {
53+
fwrite(STDERR, '[worker-' . $i . '][' . $type . '] ' . $output);
54+
});
4855
}
4956
}
5057

@@ -94,4 +101,11 @@ protected function getPackageProviders($app)
94101
{
95102
return [\Workflow\Providers\WorkflowServiceProvider::class];
96103
}
104+
105+
private static function shouldStreamWorkerOutput(): bool
106+
{
107+
$value = getenv('WORKFLOW_TEST_STREAM_WORKER_OUTPUT') ?: ($_ENV['WORKFLOW_TEST_STREAM_WORKER_OUTPUT'] ?? null);
108+
109+
return in_array($value, ['1', 'true', 'yes', 'on'], true);
110+
}
97111
}

0 commit comments

Comments
 (0)