Skip to content
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

RCORE-1974 Add tests for role/permissions changed during client reset #7840

Merged
merged 16 commits into from
Jul 18, 2024

Conversation

michael-wb
Copy link
Contributor

@michael-wb michael-wb commented Jun 26, 2024

What, How & Why?

This PR builds upon the existing PR #7675 and adds tests to verify the role change bootstraps that occur due to a role change while the sync session is currently processing a client reset.

Fixes #7328

☑️ ToDos

  • [] 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed
  • [ ] bindgen/spec.yml, if public C++ API changed

@michael-wb michael-wb self-assigned this Jun 26, 2024
@cla-bot cla-bot bot added the cla: yes label Jun 26, 2024
@michael-wb michael-wb linked an issue Jun 26, 2024 that may be closed by this pull request
Copy link

coveralls-official bot commented Jun 26, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1194

Details

  • 221 of 284 (77.82%) changed or added relevant lines in 5 files are covered.
  • 73 unchanged lines in 14 files lost coverage.
  • Overall coverage decreased (-0.009%) to 90.964%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 191 211 90.52%
src/realm/sync/config.cpp 11 54 20.37%
Files with Coverage Reduction New Missed Lines %
src/realm/object-store/shared_realm.cpp 2 91.89%
src/realm/sync/network/http.hpp 2 82.27%
src/realm/sync/client.cpp 3 91.96%
src/realm/sync/instruction_replication.cpp 3 91.48%
src/realm/sync/noinst/client_impl_base.cpp 3 82.85%
src/realm/sync/instruction_applier.cpp 4 68.01%
src/realm/sync/noinst/pending_bootstrap_store.cpp 4 94.47%
src/realm/sync/noinst/protocol_codec.hpp 4 73.3%
src/realm/bplustree.cpp 6 72.55%
src/realm/sync/noinst/server/server.cpp 6 73.56%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1191: -0.009%
Covered Lines: 215501
Relevant Lines: 236907

💛 - Coveralls

Copy link

coveralls-official bot commented Jun 27, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1196

Details

  • 217 of 280 (77.5%) changed or added relevant lines in 5 files are covered.
  • 66 unchanged lines in 15 files lost coverage.
  • Overall coverage decreased (-0.02%) to 90.958%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 187 207 90.34%
src/realm/sync/config.cpp 11 54 20.37%
Files with Coverage Reduction New Missed Lines %
test/test_index_string.cpp 1 93.48%
test/test_util_network.cpp 1 95.56%
src/realm/object-store/shared_realm.cpp 2 91.89%
src/realm/query_expression.cpp 2 86.62%
src/realm/sync/network/http.hpp 2 82.27%
src/realm/table_view.cpp 2 92.99%
src/realm/sync/noinst/server/server_history.cpp 3 63.57%
src/realm/sync/instruction_applier.cpp 4 68.45%
src/realm/sync/noinst/pending_bootstrap_store.cpp 4 94.47%
src/realm/sync/noinst/server/server.cpp 5 73.89%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1191: -0.02%
Covered Lines: 215482
Relevant Lines: 236902

💛 - Coveralls

Copy link

coveralls-official bot commented Jun 28, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1202

Details

  • 217 of 280 (77.5%) changed or added relevant lines in 5 files are covered.
  • 43 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.4%) to 90.949%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 187 207 90.34%
src/realm/sync/config.cpp 11 54 20.37%
Files with Coverage Reduction New Missed Lines %
src/realm/mixed.cpp 2 86.46%
src/realm/sync/transform.cpp 2 60.99%
src/realm/sync/noinst/protocol_codec.hpp 3 74.0%
test/fuzz_group.cpp 3 46.09%
src/realm/link_translator.cpp 4 76.92%
src/realm/sync/noinst/pending_bootstrap_store.cpp 4 94.47%
test/fuzz_tester.hpp 5 56.63%
src/realm/bplustree.cpp 7 72.39%
src/realm/sync/noinst/server/server.cpp 13 73.63%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1200: 0.4%
Covered Lines: 215526
Relevant Lines: 236974

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 1, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1220

Details

  • 217 of 280 (77.5%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on mwb/role-change-client-reset-tests at 90.989%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 187 207 90.34%
src/realm/sync/config.cpp 11 54 20.37%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1219: 91.0%
Covered Lines: 215991
Relevant Lines: 237381

💛 - Coveralls

@michael-wb
Copy link
Contributor Author

This PR is waiting for #7850 before it will be posted for review.

Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1234

Details

  • 216 of 279 (77.42%) changed or added relevant lines in 4 files are covered.
  • 663 unchanged lines in 99 files lost coverage.
  • Overall coverage decreased (-0.3%) to 90.672%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 187 207 90.34%
src/realm/sync/config.cpp 11 54 20.37%
Files with Coverage Reduction New Missed Lines %
src/realm/array.cpp 1 86.97%
src/realm/array_typed_link.hpp 1 0.0%
src/realm/object-store/dictionary.hpp 1 97.92%
src/realm/object-store/object_accessor.hpp 1 91.7%
src/realm/object-store/object.cpp 1 98.28%
src/realm/parser/driver.cpp 1 87.52%
src/realm/query_engine.hpp 1 93.93%
src/realm/set.hpp 1 76.65%
src/realm/sync/client.cpp 1 91.15%
src/realm/sync/noinst/server/crypto_server.hpp 1 0.0%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1233: -0.3%
Covered Lines: 211252
Relevant Lines: 232986

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1240

Details

  • 216 of 279 (77.42%) changed or added relevant lines in 4 files are covered.
  • 110 unchanged lines in 13 files lost coverage.
  • Overall coverage decreased (-0.03%) to 90.968%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 187 207 90.34%
src/realm/sync/config.cpp 11 54 20.37%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/network/websocket.cpp 1 71.79%
src/realm/query_expression.cpp 2 86.62%
src/realm/sync/client.cpp 3 91.14%
src/realm/sync/noinst/protocol_codec.hpp 3 73.47%
src/realm/alloc_slab.cpp 4 90.56%
src/realm/link_translator.cpp 4 76.92%
src/realm/sync/transform.cpp 4 60.92%
src/realm/util/assert.hpp 4 87.1%
src/realm/table.cpp 6 90.46%
src/realm/bplustree.cpp 7 72.39%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1239: -0.03%
Covered Lines: 215890
Relevant Lines: 237325

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 4, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1248

Details

  • 244 of 297 (82.15%) changed or added relevant lines in 4 files are covered.
  • 44 unchanged lines in 15 files lost coverage.
  • Overall coverage increased (+0.004%) to 90.987%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/flx_role_change.cpp 215 223 96.41%
src/realm/sync/config.cpp 11 56 19.64%
Files with Coverage Reduction New Missed Lines %
src/realm/array_mixed.cpp 1 94.02%
src/realm/array_string.cpp 1 88.03%
src/realm/index_string.cpp 1 84.63%
src/realm/sync/instructions.hpp 1 76.03%
src/realm/util/serializer.cpp 1 90.43%
src/realm/uuid.cpp 1 98.48%
src/realm/list.cpp 2 87.37%
src/realm/object-store/shared_realm.cpp 2 91.89%
test/test_lang_bind_helper.cpp 2 93.2%
src/realm/collection_parent.cpp 3 93.08%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1247: 0.004%
Covered Lines: 216009
Relevant Lines: 237407

💛 - Coveralls

Base automatically changed from mwb/user-role-change-tests to feature/role-change July 4, 2024 04:14
@michael-wb michael-wb force-pushed the mwb/role-change-client-reset-tests branch from 39c8e6e to 9807a39 Compare July 4, 2024 05:44
src/realm/sync/config.cpp Outdated Show resolved Hide resolved
return std::nullopt;

// Record that the error occurred
if (data.event == Event::ErrorMessageReceived) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you handle the errors in the switch below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is an early return if the update_role_state is empty, which means the role change has been performed and the test doesn't care about the current state anymore. The errors are handled above this since the 200 error will come after the role change has been triggered.
I'll add an early return in this if block, since it doesn't need to continue if an error is received.

auto set_expected_role_state = [&](ClientResetTestState state, bool skip_role_check = false) {
client_reset_state.transition_with([&](ClientResetTestState) {
update_role_state = state;
// If the role change check is skipped, the test will not look for the role change error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to track the role change bootstrap (where it makes sense) instead? we only seem to track the bootstrap of the client reset session.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the differing order of hook events depending on where the role change occurs, it is difficult to detect which bootstrap is the role change bootstrap (and sometimes it happens on the fresh realm session, while other times it happens on the primary session). Instead, the test is looking for the 200 error, which should be triggered by the role change, but it is sometimes hard to catch this using the hook event callback, especially when the session is being torn down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tracking of the client reset fresh realm bootstrap is so we can trigger the role change at different points along the client reset chain of events.

Copy link
Contributor

@jbreams jbreams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high level feedback here - i don't know what this new test case is supposed to test. just that if a role change happens at any point during a client reset, that we'll eventually succeed?

src/realm/sync/config.cpp Outdated Show resolved Hide resolved
src/realm/sync/config.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Show resolved Hide resolved
});
};

SECTION("Bind before client reset") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, i don't even know what these are testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sections are setting up the state where the role change will take place during the client reset. The entire test case will be executed for each one of these sections.

case Event::DownloadMessageIntegrated:
if (!client_reset_error)
break;
new_state = ClientResetTestState::cr_session_integrating;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of these states just seem to advance to the next state without doing anything. we check below that we reach these states, but i don't know why or what reaching the cr_session_integrating state means with respect to the behavior of this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - the current phase during the client reset is tracked so the role change can be performed when it reaches the state specified by update_role_state. I will add comments to clarify what each state means.

@michael-wb
Copy link
Contributor Author

high level feedback here - i don't know what this new test case is supposed to test. just that if a role change happens at any point during a client reset, that we'll eventually succeed?

Yes - this is verifying that if a role change happens at any point during a client reset that the data will eventually be correct once the client reset is finished.

test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
test/object-store/sync/flx_role_change.cpp Outdated Show resolved Hide resolved
bool success = !wait_for_download(*realm);
success = success && !wait_for_upload(*realm);
if (!success)
FAIL("Failed to update realm");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will produce the same data races that REQUIRE would. Catch2 isn't internally thread-safe, so we have to ensure that we're only using it from one thread at a time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is returning the wait_for_download() or wait_for_upload() result if it fails and the bool is checked under a mutex where needed.

Comment on lines 949 to 950
// Session is not valid anymore... exit now
return SyncClientHookAction::NoAction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected to happen? The hook function getting called after the SyncSession is destroyed seems like it'd be indicating a bug somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supposed to happen - I updated it to a REQUIRE(session)

Comment on lines 1138 to 1141
SECTION("Client reset session ident") {
logger->debug("ROLE CHANGE: Role change after client reset session IDENT");
// Trigger the role change just after the IDENT message is sent for the fresh realm
// download session.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is three different descriptions of what the test is testing, with the most important one being the least useful description. It's okay for SECTION titles to be pretty long-winded, and if you're finding it useful to log information in each section it's a pretty strong sign that you should just put that information in the section name. Some of these comments have some details that make sense as a comment, but for a lot of them a slightly reworded version of the comment should just be the section name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cleaned up the section names and the comments - I left the (redundant) debug statements in since it makes it easier to track down which test was being run when the failure occurred - but they have been updated to return the same text as the section name.

Copy link
Contributor

@ironage ironage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michael-wb michael-wb merged commit 1ed42eb into feature/role-change Jul 18, 2024
41 checks passed
@michael-wb michael-wb deleted the mwb/role-change-client-reset-tests branch July 18, 2024 13:15
michael-wb pushed a commit that referenced this pull request Jul 19, 2024
* RCORE-1872 Sync client should allow server bootstrapping at any time (#7440)
* First round of changes for server-initiated bootstraps
* Added test for role change bootstraps
* Updated test for handle role bootstraps
* Updated baas/baasaas to use branch with fixes
* Updated test to verify bootstrap actually occurred
* Fixed tsan warning
* Updates from review; added comments to clarify bootstrap detection logic
* Reverted baas branch to master and protocol version to 12
* Added comments to changes needed when merging to master; update baas version to not use master
* Pulled over changes from other branch and tweaking download params
* Refactored tests to validate different bootstrap types
* Updated tests to get passing using the server params
* Updated to support new batch_state protocol changes; updated tests
* Updated role change tests and merged test from separate PR
* Fixed issue with flx query verion 0 not being treated as a bootstrap
* Cleaned up the tests a bit and reworked query version 0 handling
* Updates from review; updated batch_state for schema bootstraps
* Removed extra mutex in favor of state machine's mutex
* Increased timeout when waiting for app initial sync to complete
* Updated role change test to use test commands
* Update resume and ident message handling
* Updated future waits for the pause/resume test command
* Added session connected event for when session multiplexing is disabled
* Added wait_until() to state machine to wait for callback; updated role change test

* RCORE-1973 Add role/permissions tests for new bootstrap feature (#7675)
* Moved role change tests to separate test file
* Fixed building of new flx_role_change.cpp file
* Added local changes w/role bootstrap test - fixed exception in subscription store during server initiated boostrap
* Updated local change test to include valid offline writes during role change
* Added role change test during initial schema bootstrap
* Wrapped up role change during bootstrap tests
* Removed debug statments to fix thread sanitizer
* Updated sub state comments and reverted a minor change
* Refactored role change tests and broke out into 2 separate test cases
* Moved harness from a global to a static var in each test case
* Reverted resetting the bootstrapping subscription state back to Pending
* Updated baas to use protocol v14 and removed the feature flag for role change bootstraps
* Updated baasaas version to be a cached version
* Updated baasaas githash and reordered role change during bootstrap to check for role change bootstrap as first validation step
* Minor updates to reuse the verify_records() fcn

* RCORE-2174 Bootstrap store is not being reset if initial subscription bootstrap is interrupted by role change (#7831)
* Updated pending bootstrap store to be processed (applied or cleared) when the session or connection is restarted without restarting the Sync Session

* RCORE-1974 Add tests for role/permissions changed during client reset (#7840)
* re-applied changes after base branch was merged to feature branch
* Updates to address test failures
* Disable role change check during fresh realm download
* Updated comments for clarity
* Updates from review; added a bunch of comments to test
* Updates to role change tests per review comments
* removed ostream support for SyncClientHookEvent
@github-actions github-actions bot mentioned this pull request Jul 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for role/permissions changed during client reset
5 participants