-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
TestSubscriber, concurrent reading and writing of events #5712
Comments
There is the
|
Correction: it only defends the |
Yes, unfortunately In the |
Or Either way, looks like |
True. Or create a wrapper for |
Closing via #5713. |
Some of our tests need to wait for certain events to arrive to a TestSubscriber to detect test completion. TestSubscriber does not currently allow this, because it's not possible to access the events that it has received in thread-safe manner. What we'd like to be able to do is:
However, this sometimes fails with ConcurrentModificationException on the values list of TestSubscriber, because Awaitility is reading it while some onNext() event is being written to it.
We could do
but that is not safe, since more events may arrive after the expected number of events have all been received (especially in error cases, if extra events are produced), so the comparison may still fail with ConcurrentModificationException.
We currently use version 1.2.0, but this seems to apply at least to the 1.x branch. 2.x has changed to a custom VolatileSizeArrayList, but it's not clear to me how that would in any way solve the remaining race in the second example.
I also wonder why VolatileSizeArrayList was introduced, since the existing separate volatile size variable would seem to provide enough happens-before edges to make the waiting safe (add() -> write to valueCount, read of valueCount -> read of the list). However, my understanding of the memory model is a bit hazy, so please correct me here if I'm wrong.
The text was updated successfully, but these errors were encountered: