JUnit XML logger may crash when test that is run in separate process exits unexpectedly #5771
Labels
feature/logging
Issues related to logging test results
feature/process-isolation
Issues related to running tests in separate PHP processes
type/bug
Something is broken
version/10
Something affects PHPUnit 10
version/11
Something affects PHPUnit 11
Summary
When a test run in a separate process caused the child process to ended unexpectedly, that is without serialized output, and JUnit logging is used, the main process will crash afterwards due to an assert or subsequent type error.
Current behavior
JunitXmlLogger
works with the event system.When it receives a
PreparationStarted
event, it will initialize its internal data for the current test case.When it receives a
Finished
event, it will assert that the internal data has been initialized.When the test is run in a separate process, this all happens in that child process, which thus has its own instance of
JunitXmlLogger
.Should the child process end unexpectedly,
AbstractPhpProcess::processChildResult
will first emit anErrored
event and then aFinished
event.These two are processed by the
JunitXmlLogger
instance of the main process that never received aPreparationStarted
event.While the handler for the
Errored
event is capable to deal with that by first initializing the internal data structures for the test case, it will also call the inner handler for a finished test which resets these internal data structures.The handler for the
Finished
event does not handle initialization and thus runs into the assert.How to reproduce
minimal test case
output without
--log-junit
output with
--log-junit
output with
--log-junit
and asserts disabledExpected behavior
The assert should not fail and output stay the same even when using JUnit logging.
The fix for #5561 (which had similar symptoms) introduced a
preparationFailed
flag (which is never cleared once set; another potential bug?) which is used to skip the inner handler for theFinished
event (inJunitXmlLogger::testFinished
).I'm not sure why this flag was introduced instead of just checking the
prepared
flag, however checking the latter in that place seems to solve the issue.The text was updated successfully, but these errors were encountered: