TestCorruptDbConfigHandling: - Create persistent config rest tester - Create a db with a non-corrupt config - Grab the persisted config from the bucket for purposes of changing the bucket name on it (this simulates a dbconfig becoming corrupt) - Update the persisted config to change the bucket name
(t *testing.T)
| 949 | // - assert the db returns to the server context and is removed from corrupt database tracking AND that the bucket name |
| 950 | // on the config now matches the rest tester bucket name |
| 951 | func TestCorruptDbConfigHandling(t *testing.T) { |
| 952 | base.LongRunningTest(t) |
| 953 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyConfig) |
| 954 | |
| 955 | rt := rest.NewRestTester(t, &rest.RestTesterConfig{ |
| 956 | CustomTestBucket: base.GetTestBucket(t), |
| 957 | PersistentConfig: true, |
| 958 | MutateStartupConfig: func(config *rest.StartupConfig) { |
| 959 | // configure the interval time to large interval, so it doesn't run during test |
| 960 | config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(10 * time.Minute) |
| 961 | }, |
| 962 | }) |
| 963 | defer rt.Close() |
| 964 | ctx := base.TestCtx(t) |
| 965 | |
| 966 | // create db with correct config |
| 967 | dbConfig := rt.NewDbConfig() |
| 968 | resp := rt.CreateDatabase("db1", dbConfig) |
| 969 | rest.RequireStatus(t, resp, http.StatusCreated) |
| 970 | |
| 971 | // grab the persisted db config from the bucket |
| 972 | databaseConfig := rest.DatabaseConfig{} |
| 973 | _, err := rt.ServerContext().BootstrapContext.GetConfig(rt.Context(), rt.CustomTestBucket.GetName(), rt.ServerContext().Config.Bootstrap.ConfigGroupID, "db1", &databaseConfig) |
| 974 | require.NoError(t, err) |
| 975 | |
| 976 | // update the persisted config to a fake bucket name |
| 977 | newBucketName := "fakeBucket" |
| 978 | _, err = rt.UpdatePersistedBucketName(&databaseConfig, &newBucketName) |
| 979 | require.NoError(t, err) |
| 980 | |
| 981 | // force reload of configs from bucket |
| 982 | rt.ServerContext().ForceDbConfigsReload(t, ctx) |
| 983 | |
| 984 | // assert that the in memory representation of the db config on the server context is gone now we have broken the config |
| 985 | responseConfig := rt.ServerContext().GetDbConfig("db1") |
| 986 | assert.Nil(t, responseConfig) |
| 987 | |
| 988 | require.Len(t, rt.ServerContext().AllInvalidDatabaseNames(t), 1) |
| 989 | |
| 990 | // assert that fetching config fails with the correct error message to the user |
| 991 | resp = rt.SendAdminRequest(http.MethodGet, "/db1/_config", "") |
| 992 | rest.RequireStatus(t, resp, http.StatusNotFound) |
| 993 | assert.Contains(t, resp.Body.String(), "You must update database config immediately") |
| 994 | |
| 995 | // assert trying to delete fails with the correct error message to the user |
| 996 | resp = rt.SendAdminRequest(http.MethodDelete, "/db1/", "") |
| 997 | rest.RequireStatus(t, resp, http.StatusNotFound) |
| 998 | assert.Contains(t, resp.Body.String(), "You must update database config immediately") |
| 999 | |
| 1000 | // correct the name through update to config |
| 1001 | resp = rt.ReplaceDbConfig("db1", dbConfig) |
| 1002 | rest.RequireStatus(t, resp, http.StatusNotFound) |
| 1003 | assert.Contains(t, resp.Body.String(), "You must update database config immediately") |
| 1004 | |
| 1005 | // create db of same name with correct db config to correct the corrupt db config |
| 1006 | resp = rt.CreateDatabase("db1", dbConfig) |
| 1007 | rest.RequireStatus(t, resp, http.StatusCreated) |
| 1008 |
nothing calls this directly
no test coverage detected