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.
I don't think this test is quite correctly specified.
The semantics of
flatMapParSwitchare that it is supposed to maintain the target parallelism but unlikeflatMapPar, which would wait for the previous child streams to complete before opening new ones, it should interrupt the oldest child stream to allow a new one to be opened while maintaining the target parallelism.In this test we are creating 12 child streams with
flatMapParSwitchwith a parallelism of 4. The first 8 never complete and the last 4 increment aRef. So we are testing that the first 8 child streams will be terminated and that the last four complete.However, if one of the last four child streams completes before all of them are opened then we don't actually need to terminate one of the previous child streams to maintain the target parallelism and could suspend indefinitely.
This doesn't actually occur today because the current implementation always terminates the oldest child stream when we open a new child stream, even if that is not necessary to stay within the bounded parallelism. However, at the very least this seems like a guarantee that should not be relied on so I don't think we should be testing for it.
Instead we can use a
Promiseto make sure that all four of the last child streams are open at the same time, which would require closing all of the other child streams.