-
Notifications
You must be signed in to change notification settings - Fork 31
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
try to catch issue with subjects #697
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ddd6e9a
try to catch issue
victimsnino 1529116
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a0691f6
Update test_subjects.cpp
victimsnino ae5cbc7
Update test_subjects.cpp
victimsnino 7b0bc3c
Update test_subjects.cpp
victimsnino 73c834e
fix
victimsnino b2bd784
fix
victimsnino 5dba2e2
fix
victimsnino f180ef3
speedup
victimsnino 622be88
fix
victimsnino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,26 @@ TEST_CASE("subject can be modified from on_next call") | |
} | ||
} | ||
|
||
TEST_CASE("subject handles addition from inside on_next properly") | ||
{ | ||
rpp::subjects::publish_subject<int> subject{}; | ||
|
||
SUBCASE("subscribe inside on_next") | ||
{ | ||
int value = {}; | ||
subject.get_observable().subscribe([&subject, &value](int v) { | ||
for (int i = 0; i < 100; ++i) | ||
subject.get_observable().subscribe([](int) {}); | ||
value = v; | ||
Comment on lines
+179
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve subscription management in test The test creates 100 subscriptions without proper cleanup, which could lead to resource leaks. Apply this diff to properly manage subscriptions: - for (int i = 0; i < 100; ++i)
- subject.get_observable().subscribe([](int) {});
+ auto d = rpp::composite_disposable_wrapper::make();
+ for (int i = 0; i < 100; ++i)
+ subject.get_observable().subscribe(d, [](int) {});
|
||
}); | ||
|
||
for (int i = 0; i < 100; ++i) | ||
subject.get_observer().on_next(i); | ||
|
||
REQUIRE(value == 99); | ||
} | ||
} | ||
|
||
TEST_CASE("publish subject caches error/completed") | ||
{ | ||
auto mock = mock_observer_strategy<int>{}; | ||
|
Oops, something went wrong.
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.
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.
Critical: Fix potential race conditions and iterator invalidation
The current implementation has several thread-safety issues:
size
and releasing the lock creates a time window where the deque could be modified, making the size inconsistent with the actual number of observers.Consider this safer implementation:
This solution:
📝 Committable suggestion