Fix a floating error in the WorkerRestart test #542
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's wrong
The
WorkerRestartTesthas a floating error (race condition between phpunit runtime and runtime into Roadrunner workers activity). TheWorkerRestartTestis unstable.How it works now:
The key-value cache (
StorageInterface) has an in-memory implementation. Therefore set values are reset upon roadrunner restart.KV_ACTIVITY_BLOCKEDis set totrue2.1.
$runner->stop();,KV_ACTIVITY_BLOCKEDkey is reset, because storage is in-memory2.2.
$runner->start();2.3. Roadrunner starts the workers which may execute activity code immediately
KV_ACTIVITY_BLOCKEDis set tofalse)The activity code throws an exception, if key
KV_ACTIVITY_BLOCKEDhas a value that is not boolean (nullby default if key does't exists).What's the problem
If step
3starts before step2.2, the test will pass.But if an activity on step
2.3in a roadrunner worker starts executing before step 3, (race condition), the test fails withApplicationFailureKV BLOCKED key not set exception.It depends only on the test execution environment and on the luck.
Proposed solution
By default the activity is blocked, no matter if a value in the cache exists. The activity is only unblocked after setting the
KV_ACTIVITY_BLOCKEDkey tofalse. No exception is thrown.Also the problem would not exist if the storage was persistent of course.