-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed before and after class methods also called from primary process when test class or method is run in separated process. #6041
base: main
Are you sure you want to change the base?
Conversation
… when test class or method is run in separated process.
That would be #5230. |
Please target the |
…lved issue with after class method.
I've added a test and fixed after class being called twice. How do I target this branch? Checked out only master. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6041 +/- ##
=========================================
Coverage 94.69% 94.69%
- Complexity 6456 6463 +7
=========================================
Files 697 697
Lines 20307 20311 +4
=========================================
+ Hits 19229 19234 +5
+ Misses 1078 1077 -1 ☔ View full report in Codecov by Sentry. |
|
||
//#[RunTestsInSeparateProcesses] | ||
#[RunClassInSeparateProcess] | ||
final class BeforeAndAfterClassMethodCallCountTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simillar test would be good for a class with some tests run in a separate process and some not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests will fail cause before and after method will be called multiple times when TestSuite
is executed in another process. Purpose of this fix was to prevent main process executing before and after class methods when attribute is set. I don't have atm time to fix the issue with process isolation executing these functions multiple times, it requires a bit of redesign.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I mean to have simillar test for all usecases - for RunClassInSeparateProcess
attribute when all tests are run in a separate process and also when tests within a class are run in a separate process only partly.
I've fixed all the issues with separated process handling. Re-implemented separated process class template and added extra tests to validate all the before and after class methods are properly called. New class template is missing these setters. I don't know if they are needed. Please comment
|
@@ -69,52 +72,67 @@ function __phpunit_run_isolated_test() | |||
|
|||
ErrorHandler::instance()->useDeprecationTriggers($deprecationTriggers); | |||
|
|||
$test = new {className}('{name}'); | |||
ini_set('xdebug.scream', '0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line fixing a separate problem and should be separated from this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well problem began with PHPUnit calling before and after class methods from primary process when run in separated process. After fixing the issue I stumbled on another one where those methods are called for every test while RunClassInSeparateProcess
is defined. So yes, this PR contains fixes to before and after class methods being falsely called while using RunTestsInSeparateProcesses
, RunClassInSeparateProcess
and RunInSeparateProcess
attribute.
Both of those templates (class.tpl
, method.tpl
) where diff identical and class template was invalid for those cases and causing undesired behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more clear: my question was about this specific xdebug line.
Was this moved from elsewhere or is this a line we need for the after/before methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was in the source before my redesign. Copied common functionality from previous version.
$test->setData('{dataName}', unserialize('{data}'));
$test->setDependencyInput(unserialize('{dependencyInput}'));
These lines I don't known what they do. Are they for proxing primary process global state?
Our project now runs all the tests properly without any issues. We have suites without and with separated process. Also mixed tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$test->setData('{dataName}', unserialize('{data}')); $test->setDependencyInput(unserialize('{dependencyInput}'));
These lines I don't known what they do.
They pass data from data providers and depended-upon tests to the test.
Please fix the coding guidelines violations. |
Weird behavior when project is pulled on Windows. |
This pull request has grown quite a bit since it was first proposed, making it hard to review. For instance, the change from an array to an object structure seems to be unrelated to problems that you want to address. And "problems" is a problem: this pull request addressed multiple problems. It would be easier to review smaller, more focused pull requests. |
Well this pull request can't be split cause changes are related to each other. Running tests in a separated process would have returned an array containing arrays with tests information. To distinguish it from method template returning test data in an array, I changed returning array to object in both templates. Tests in separated process return array containing objects and method returns object. |
Please have a look at the failing tests. |
Added a check for skipped and incomplete tests. This 'improvement' is kinda as is and can't be done the right way at the moment. |
Thank you for looking into the tests. However, I am unable to review this pull request which seems to get bigger and bigger. |
Bigger? 5 files have changed + tests.
If this is counted a big change then I don't know what is a small change. This change cannot be made smaller cause |
da21665
to
4dddc8c
Compare
} | ||
|
||
Facade::instance()->forward($childResult['events']); | ||
PassedTests::instance()->import($childResult['passedTests']); | ||
foreach ($childResult as $result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this array to object transformation be extracted into a separate refactoring PR, without the actual bugfix?
I try to find ideas on how we can make this PR smaller and manageable
Our project uses heavily
define
constants in multiple sub modules and integration tests are ran inside separated test class process usingRunClassInSeparateProcess
attribute. EveryTestCase
sets its own defines (constants) insetUpBeforeClass
, but PHPUnit calls the function on every registeredTestCase
from primary process thus failing to initialize sub module resources after first call, and primary test process receives an exception (e.g. invalid path).Before and after class methods must not be called at all from primary process if the tests are ran inside separated process (sandbox).
Also there is a issue with the
src/Framework/TestRunner/templates/class.tpl
. Idk if the parameterRunClassInSeparateProcess
isn't properly implemented, but the template is for sure invalid when set andsetUpBeforeClass
is called for every test defined inTestCase
.