Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Nov 20, 2024
1 parent 637509e commit ce2a441
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
11 changes: 8 additions & 3 deletions src/meta/server_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,13 @@ void server_state::set_app_envs(const app_env_rpc &env_rpc)
zauto_write_lock l(_lock);
std::shared_ptr<app_state> app = get_app(app_name);

FAIL_POINT_INJECT_NOT_RETURN_F("set_app_envs_failed", [&app](std::string_view s) {
if (s == "dropped_after_update_remote_storage") {
app.reset();
return;
}
});

// The table might be removed just before the callback function is invoked, thus we must
// check if this table still exists.
//
Expand All @@ -3078,9 +3085,7 @@ void server_state::set_app_envs(const app_env_rpc &env_rpc)
// dropped state. Once it is applied by remote storage after another update dropping
// the table, the state of the table would always be non-dropped on remote storage.
if (!app) {
LOG_ERROR("set app envs failed since app(name={}, id={}) has just been dropped",
app_name,
app->app_id);
LOG_ERROR("set app envs failed since app({}) has just been dropped", app_name);
env_rpc.response().err = ERR_APP_DROPPED;
env_rpc.response().hint_message = "app has just been dropped";
return;
Expand Down
48 changes: 30 additions & 18 deletions src/meta/test/server_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,36 @@ class server_state_test
void meta_service_test_app::app_envs_basic_test()
{
server_state_test test;
test.load_apps({"test_app1", "test_set_app_envs_not_found"});

std::cout << "test server_state::set_app_envs(not_found)..." << std::endl;
{
configuration_update_app_env_request request;
request.__set_app_name("test_set_app_envs_not_found");
request.__set_op(app_env_operation::type::APP_ENV_OP_SET);
request.__set_keys({replica_envs::ROCKSDB_WRITE_BUFFER_SIZE});
request.__set_values({"67108864"});

fail::setup();
fail::cfg("set_app_envs_failed", "void(not_found)");

auto rpc = test.set_app_envs(request);
ASSERT_EQ(ERR_APP_NOT_EXIST, rpc.response().err);

fail::teardown();
}
test.load_apps({"test_app1",
"test_set_app_envs_not_found",
"test_set_app_envs_dropping",
"test_set_app_envs_dropped_after_update_remote_storage"});

#define TEST_SET_APP_ENVS_FAILED(action, err_code) \
std::cout << "test server_state::set_app_envs(" #action ")..." << std::endl; \
do { \
configuration_update_app_env_request request; \
request.__set_app_name("test_set_app_envs_" #action); \
request.__set_op(app_env_operation::type::APP_ENV_OP_SET); \
request.__set_keys({replica_envs::ROCKSDB_WRITE_BUFFER_SIZE}); \
request.__set_values({"67108864"}); \
\
fail::setup(); \
fail::cfg("set_app_envs_failed", "void(" #action ")"); \
\
auto rpc = test.set_app_envs(request); \
ASSERT_EQ(err_code, rpc.response().err); \
\
fail::teardown(); \
} while (0)

TEST_SET_APP_ENVS_FAILED(not_found, ERR_APP_NOT_EXIST);

TEST_SET_APP_ENVS_FAILED(dropping, ERR_BUSY_DROPPING);

TEST_SET_APP_ENVS_FAILED(dropped_after_update_remote_storage, ERR_APP_DROPPED);

#undef TEST_SET_APP_ENVS_FAILED

std::cout << "test server_state::set_app_envs()..." << std::endl;
{
Expand Down

0 comments on commit ce2a441

Please sign in to comment.