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-1973 Add role/permissions tests for new bootstrap feature #7675

Open
wants to merge 28 commits into
base: feature/role-change
Choose a base branch
from

Conversation

michael-wb
Copy link
Contributor

@michael-wb michael-wb commented May 3, 2024

What, How & Why?

Moved the role change bootstrap tests to their own file and reduced the number of times the App was created and destroyed during the tests.
Additional tests for the server initiated bootstraps; specifically for role change bootstraps:

  • "Pending changes are lost if not allowed after role change" - Verify pending local changes are either recovered or lost during role change depending on whether changes are still in view after role change.
  • "Role changes during bootstrap complete successfully" - Verify role change during initial schema and subscriptions bootstraps complete successfully and have the correct data.

Fixes #7327

☑️ 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 May 3, 2024
@cla-bot cla-bot bot added the cla: yes label May 3, 2024
@michael-wb michael-wb linked an issue May 3, 2024 that may be closed by this pull request
Copy link

coveralls-official bot commented May 3, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1094

Details

  • 157 of 157 (100.0%) changed or added relevant lines in 2 files are covered.
  • 47 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.3%) to 90.761%

Files with Coverage Reduction New Missed Lines %
src/realm/sort_descriptor.cpp 1 94.06%
test/test_table.cpp 1 99.51%
src/realm/table_view.cpp 2 92.99%
src/realm/sync/noinst/server/server_history.cpp 3 63.51%
src/realm/table.cpp 3 90.08%
src/realm/bplustree.cpp 6 72.55%
src/realm/sync/noinst/client_impl_base.cpp 7 82.36%
src/realm/sync/noinst/server/server.cpp 7 73.89%
test/fuzz_group.cpp 17 55.02%
Totals Coverage Status
Change from base Build michael.wilkersonbarker_1088: 0.3%
Covered Lines: 212810
Relevant Lines: 234473

💛 - Coveralls

Base automatically changed from mwb/role-change-bootstraps to feature/role-change June 11, 2024 17:13
@michael-wb michael-wb marked this pull request as ready for review June 19, 2024 04:14
@@ -1208,10 +1212,24 @@ void SessionWrapper::on_flx_sync_progress(int64_t new_version, DownloadBatchStat
return;
}
REALM_ASSERT(!m_finalized);
REALM_ASSERT(new_version >= m_flx_last_seen_version);
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't new_version always be either m_flx_last_seen_version, m_flx_active_version or m_flx_active_version+1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a query bootstrap is in progress when a server initiated bootstrap takes place (which cancels the current query bootstrap), m_flx_last_seen_version will be m_flx_active_version + 1 while new_version will be m_flx_active_version and this assertion will fail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's still one of the cases I mentioned. I was proposing we update the assert, not keep the deleted one.

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 m_flx_last_seen_version can actually be greater than m_flx_active_version + 1 in the case of a QUERY_ERROR response and it always starts out at 0 when the session is started until the first download message is received. Since the current validation and checking for server-initiated bootstrap logic is valid, I am going to leave this as-is.

Copy link
Collaborator

@danieltabacaru danieltabacaru Jun 19, 2024

Choose a reason for hiding this comment

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

It seems that m_flx_last_seen_version should be updated when we get a query error then. m_flx_active_version is initialized though when the SessionWrapper is actualized. Either way, your call.

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 would update it, but this is a change that might affect progress notifications, which uses this value. I created RCORE-2173 to handle updating this separately if we want to update it.

if (!harness) {
return; // nothing to do
}
harness->app()->sync_manager()->wait_for_sessions_to_terminate();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to explicitly wait for sessions to terminate?

Copy link
Contributor Author

@michael-wb michael-wb Jun 28, 2024

Choose a reason for hiding this comment

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

I don't think we need to - this was copied over from another test case that reused the harness across its sections. This entire function was removed.

return; // nothing to do
}
harness->app()->sync_manager()->wait_for_sessions_to_terminate();
harness.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we re-use the harness unique_ptr? Why not just take the unique_ptr by value and let it go out of scope? Why have this function at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A single harness is re-used across the sections within a test_case. I ended up removing this function and just call harness.reset() in the last section.

case Event::ErrorMessageReceived:
REQUIRE(cur_state == TestState::start);
REQUIRE(data.error_info);
REQUIRE(data.error_info->raw_error_code == 200);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we compare the error_code rather than the raw_error_code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a ProtocolErrorInfo struct, which doesn't have error_code; only raw_error_code is available.

state_machina.transition_with([&](TestState cur_state) {
switch (expected.bootstrap) {
case BootstrapMode::NoReconnect:
// Confirm that the session did receive an error and a bootstrap did not occur
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we confirm that we received an error? Should the name of this enum value be NoBootstrapNoError or something? Not sure what NoReconnect actually means here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to NoErrorNoBootstrap and updated comment

REQUIRE_FALSE(role_change_bootstrap);
break;
case BootstrapMode::None:
// Confirm that a bootstrap nor a client reset did not occur
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is something like NoBootstrapReceivedError? "Confirm that neither a bootstrap nor a client rest did not occur" seems like a double negative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed state to GotErrorNoBootstrap and updated comment

update_perms_and_verify(*harness, realm_1, test_rules,
{BootstrapMode::Any, params.num_emps, params.num_mgrs, 0});

// Realm 2 data should not change (and there shouldn't be any bootstrap messages)
Copy link
Contributor

Choose a reason for hiding this comment

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

If there shouldn't be any bootstrap messages, why do we pass BootstrapMode::Any to update_perms_and_verify above?

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 added a comment for this - realm_1 should receive a role change bootstrap, but realm_2 should not (and there is a on_sync_client_event_hook fcn for realm_2 that verifies this).

update_perms_and_verify(*harness, realm_1, test_rules,
{BootstrapMode::Any, params.num_emps, params.num_mgrs, params.num_dirs});

// Realm 2 data should not change (and there shouldn't be any bootstrap messages)
Copy link
Contributor

Choose a reason for hiding this comment

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

If there shouldn't be any bootstrap messages, why do we pass BootstrapMode::Any to update_perms_and_verify above? Or am I mis-understanding the meaning of BootstrapMode::Any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BootstrapMode::Any means that a bootstrap is expected, but we don't care what type of bootstrap (single message, multi message, etc.) occurs.

if (cur_state == BootstrapTestState::not_ready)
return std::nullopt;

std::optional<BootstrapTestState> new_state = std::nullopt;
Copy link
Contributor

Choose a reason for hiding this comment

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

this will default initialize to std::nullopt.


case Event::ErrorMessageReceived:
REQUIRE(data.error_info);
if (data.error_info->raw_error_code == 200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

are there other errors we could receive here that we don't want to track?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really - changed the if to a REQUIRE()

break;

case Event::ErrorMessageReceived:
REQUIRE(data.error_info);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just assume the sync client will do the right thing here.

return harness;
}

void teardown_harness(std::unique_ptr<FLXSyncTestHarness>& harness)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should not be a reference and instead pass the ownership because it's not expected to use the harness after calling this function.

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 actually removed this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add role/permissions tests for new bootstrap feature
3 participants