-
Notifications
You must be signed in to change notification settings - Fork 4k
Add opt in initial check run #14087
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
Closed
Closed
Add opt in initial check run #14087
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| %% This Source Code Form is subject to the terms of the Mozilla Public | ||
| %% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| %% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| %% | ||
| %% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. | ||
| %% | ||
|
|
||
| %% Test suite for the prevent_startup_if_node_was_reset feature. | ||
| %% This feature helps detect potential data loss scenarios by maintaining | ||
| %% a marker file to track if a node has been initialized before. | ||
|
|
||
| -module(node_initial_run_SUITE). | ||
|
|
||
| -include_lib("common_test/include/ct.hrl"). | ||
| -include_lib("eunit/include/eunit.hrl"). | ||
|
|
||
| -compile(export_all). | ||
|
|
||
| all() -> | ||
| [ | ||
| {group, single_node_mnesia}, | ||
| {group, single_node_khepri} | ||
| ]. | ||
|
|
||
| groups() -> | ||
| [ | ||
| {single_node_mnesia, [], [ | ||
| prevent_startup_if_node_was_reset_disabled, | ||
| prevent_startup_if_node_was_reset_enabled | ||
| ]}, | ||
| {single_node_khepri, [], [ | ||
| prevent_startup_if_node_was_reset_disabled, | ||
| prevent_startup_if_node_was_reset_enabled | ||
| ]} | ||
| ]. | ||
|
|
||
| %% ------------------------------------------------------------------- | ||
| %% Testsuite setup/teardown. | ||
| %% ------------------------------------------------------------------- | ||
|
|
||
| init_per_suite(Config) -> | ||
| rabbit_ct_helpers:log_environment(), | ||
| rabbit_ct_helpers:run_setup_steps(Config). | ||
|
|
||
| end_per_suite(Config) -> | ||
| rabbit_ct_helpers:run_teardown_steps(Config). | ||
|
|
||
| init_per_group(Groupname, Config) -> | ||
| Config0 = rabbit_ct_helpers:set_config(Config, [ | ||
| {metadata_store, meta_store(Groupname)}, | ||
| {rmq_nodes_clustered, false}, | ||
| {rmq_nodename_suffix, Groupname}, | ||
| {rmq_nodes_count, 1} | ||
| ]), | ||
| rabbit_ct_helpers:run_steps( | ||
| Config0, | ||
| rabbit_ct_broker_helpers:setup_steps() ++ | ||
| rabbit_ct_client_helpers:setup_steps() | ||
| ). | ||
|
|
||
| end_per_group(_, Config) -> | ||
| rabbit_ct_helpers:run_steps( | ||
| Config, | ||
| rabbit_ct_client_helpers:teardown_steps() ++ | ||
| rabbit_ct_broker_helpers:teardown_steps() | ||
| ). | ||
|
|
||
| init_per_testcase(Testcase, Config) -> | ||
| rabbit_ct_helpers:testcase_started(Config, Testcase), | ||
| Config. | ||
|
|
||
| end_per_testcase(Testcase, Config) -> | ||
| rabbit_ct_helpers:testcase_finished(Config, Testcase). | ||
|
|
||
| %% ------------------------------------------------------------------- | ||
| %% Test cases | ||
| %% ------------------------------------------------------------------- | ||
|
|
||
| prevent_startup_if_node_was_reset_disabled(Config) -> | ||
| % When feature is disabled (default), node should start normally | ||
| DataDir = rabbit_ct_broker_helpers:get_node_config(Config, 0, data_dir), | ||
| MarkerFile = filename:join(DataDir, "node_initialized.marker"), | ||
| % Setting is disabled so no marker file should be present | ||
| ?assertNot(filelib:is_file(MarkerFile)), | ||
|
|
||
| % Restarting the node should work fine | ||
| ok = stop_app(Config), | ||
| set_env(Config, false), | ||
| ok = start_app(Config), | ||
| % Still no marker file | ||
| ?assertNot(filelib:is_file(MarkerFile)), | ||
| ok. | ||
|
|
||
| prevent_startup_if_node_was_reset_enabled(Config) -> | ||
| DataDir = rabbit_ct_broker_helpers:get_node_config(Config, 0, data_dir), | ||
| MarkerFile = filename:join(DataDir, "node_initialized.marker"), | ||
|
|
||
| ok = stop_app(Config), | ||
| set_env(Config, true), | ||
| ok = start_app(Config), | ||
| % Setting is enabled so marker file should be present after initial startup | ||
| ?assert(filelib:is_file(MarkerFile)), | ||
|
|
||
| % Restarting the node should be fine, as there is a marker file | ||
| % and corresponding schema data (consistent state) | ||
|
|
||
| ok = stop_app(Config), | ||
| ok = start_app(Config), | ||
|
|
||
| SchemaFile = schema_file(Config), | ||
|
|
||
| ?assert(filelib:is_file(MarkerFile)), | ||
|
|
||
| % Stop the node and remove the present schema to simulate data loss | ||
| ok = stop_app(Config), | ||
| file:delete(SchemaFile), | ||
| % Node should fail to start because marker exists but schema is missing, | ||
| % indicating potential data loss or corruption | ||
| ?assertMatch( | ||
| {error, 69, _}, | ||
| start_app(Config) | ||
| ), | ||
| ok. | ||
|
|
||
| %% ------------------------------------------------------------------- | ||
| %% Internal helpers | ||
| %% ------------------------------------------------------------------- | ||
|
|
||
| stop_app(Config) -> | ||
| Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), | ||
| case rabbit_ct_broker_helpers:rabbitmqctl(Config, Node, ["stop_app"]) of | ||
| {ok, _} -> ok; | ||
| Error -> Error | ||
| end. | ||
|
|
||
| start_app(Config) -> | ||
| Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), | ||
| case rabbit_ct_broker_helpers:rabbitmqctl(Config, Node, ["start_app"]) of | ||
| {ok, _} -> ok; | ||
| Error -> Error | ||
| end. | ||
|
|
||
| maybe_enable_prevent_startup_if_node_was_reset(Config, prevent_startup_if_node_was_reset_enabled) -> | ||
| rabbit_ct_helpers:merge_app_env( | ||
| Config, {rabbit, [{prevent_startup_if_node_was_reset, true}]} | ||
| ); | ||
| maybe_enable_prevent_startup_if_node_was_reset(Config, _) -> | ||
| Config. | ||
|
|
||
| meta_store(single_node_mnesia) -> | ||
| mnesia; | ||
| meta_store(single_node_khepri) -> | ||
| khepri. | ||
|
|
||
| schema_file(Config) -> | ||
| DataDir = rabbit_ct_broker_helpers:get_node_config(Config, 0, data_dir), | ||
| MetaStore = rabbit_ct_helpers:get_config(Config, metadata_store), | ||
| case MetaStore of | ||
| mnesia -> | ||
| filename:join(DataDir, "schema.DAT"); | ||
| khepri -> | ||
| NodeName = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), | ||
| filename:join([DataDir, "coordination", NodeName, "names.dets"]) | ||
| end. | ||
|
|
||
| set_env(Config, Bool) -> | ||
| Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), | ||
| ok = rpc:call(Node, application, set_env, [rabbit, prevent_startup_if_node_was_reset, Bool]). |
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.
I'd also rename this to
prevent_startup_if_node_was_reset.