Browser plugin: keep the Playwright server's output when it crashes
I maintainer di solito rispondono entro 5 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Inizia leggendo src/Playwright/Servers/PlaywrightNpmServer.php in pestphp/pest-plugin-browser, soprattutto per capire come viene avviato il processo del server e come rileva la riga che indica che è in ascolto. Controlla i test esistenti per PlaywrightNpmServer e aggiungi test per la scrittura dei log nel file configurato e il rilevamento all’avvio; il lavoro è completato quando il log registra l’output se PEST_BROWSER_SERVER_LOG è impostato, mentre il comportamento quando non è impostato rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
PlaywrightNpmServer reads the Playwright server's output through a pipe held by the test process. When the server crashes mid-suite, whatever it printed last is lost with the pipe: the suite reports hundreds of Client unexpectedly closed failures and nothing says why the server went down.
Proposal
An opt-in environment variable, PEST_BROWSER_SERVER_LOG. When it names a file, the server command appends its stdout and stderr to that file as it comes, and startup detection reads the "listening" line from the file instead of the pipe. When the variable is unset, nothing changes.
Why a file
A file survives the process that wrote it. After a crash the last lines are still there, and a CI job can keep them as an artifact.
Patch
About 35 lines in src/Playwright/Servers/PlaywrightNpmServer.php of pestphp/pest-plugin-browser (written against 5.0.1). We have been running it since early November on a large browser suite across 6 parallel processes. Happy to open a pull request against 5.x if the approach suits you.
Diff
diff --git a/src/Playwright/Servers/PlaywrightNpmServer.php b/src/Playwright/Servers/PlaywrightNpmServer.php
--- a/src/Playwright/Servers/PlaywrightNpmServer.php
+++ b/src/Playwright/Servers/PlaywrightNpmServer.php
@@ -24,6 +24,11 @@
private const string PLAYWRIGHT_VERSION = '1.62.1';
/**
+ * The environment variable naming the file the server's output is appended to.
+ */
+ public const string LOG = 'PEST_BROWSER_SERVER_LOG';
+
+ /**
* The underlying process instance, if any.
*/
private ?SystemProcess $systemProcess = null;
@@ -60,11 +65,27 @@
return;
}
- $this->systemProcess = SystemProcess::fromShellCommandline(sprintf(
+ $command = sprintf(
$this->command,
$this->host,
$this->port,
- ), $this->baseDirectory, [
+ );
+
+ // The file the server's output is appended to as it comes, when one is
+ // named: the output a pipe holds is lost with the process that reads it,
+ // and a server that crashes writes nothing once it is gone.
+ $log = getenv(self::LOG);
+ $log = is_string($log) && $log !== '' ? $log : null;
+ $offset = 0;
+
+ if ($log !== null) {
+ $command .= ' >> '.escapeshellarg($log).' 2>&1';
+
+ clearstatcache(true, $log);
+ $offset = is_file($log) ? (int) filesize($log) : 0;
+ }
+
+ $this->systemProcess = SystemProcess::fromShellCommandline($command, $this->baseDirectory, [
'APP_URL' => sprintf('http://%s:%d', $this->host, $this->port),
]);
@@ -72,10 +93,22 @@
$this->systemProcess->start();
- $this->systemProcess->waitUntil(
- fn (string $type, string $output): bool => str_contains($output, $this->until)
- );
+ if ($log === null) {
+ $this->systemProcess->waitUntil(
+ fn (string $type, string $output): bool => str_contains($output, $this->until)
+ );
+ } else {
+ while ($this->isRunning()) {
+ $written = @file_get_contents($log, false, null, $offset);
+ if (is_string($written) && str_contains($written, $this->until)) {
+ break;
+ }
+
+ usleep(10_000);
+ }
+ }
+
if ($this->isRunning() === false) {
self::ensurePlaywrightIsInstalledAndVersionIsSupported();
- Lingua principale
- PHP
- Stelle
- 11.8k
- Fork
- 559
- Merge medio
- 5g 23h
- PR unite (30g)
- 24
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pestphp/pest
-
[Bug]: --mutate hides unreadable files, so mutants behind a failed read can never be killedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 5 giorni
-
[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endingsForse già presa @webdevsamran l’ha presa 57 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 5 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 5 giorni
-
[pest-plugin-browser] Page::waitForLoadState() never sends its message — waitForEvent() is a silent no-opForse già presa @asllanmaciel l’ha presa 70 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
pestphp/pest#1892 · 2 commenti ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di pestphp/pest
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
mailcow/mailcow-dockerized#7668 · 5 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
lara-zeus/spatie-translatable#80 ·
I maintainer di solito rispondono entro 1 giorno
-
small
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
uiowa/uiowa#10296 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
asyncapi/modelina#2709 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
My-Little-Forum/mylittleforum#937 ·