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
WorkerRestartTest
has a floating error (race condition between phpunit runtime and runtime into Roadrunner workers activity). TheWorkerRestartTest
is 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_BLOCKED
is set totrue
2.1.
$runner->stop();
,KV_ACTIVITY_BLOCKED
key is reset, because storage is in-memory2.2.
$runner->start();
2.3. Roadrunner starts the workers which may execute activity code immediately
KV_ACTIVITY_BLOCKED
is set tofalse
)The activity code throws an exception, if key
KV_ACTIVITY_BLOCKED
has a value that is not boolean (null
by default if key does't exists).What's the problem
If step
3
starts before step2.2
, the test will pass.But if an activity on step
2.3
in a roadrunner worker starts executing before step 3, (race condition), the test fails withApplicationFailure
KV 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_BLOCKED
key tofalse
. No exception is thrown.Also the problem would not exist if the storage was persistent of course.