MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestDatabaseStartupFailure

Function TestDatabaseStartupFailure

rest/server_context_test.go:952–998  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

950}
951
952func TestDatabaseStartupFailure(t *testing.T) {
953 if !base.IsEnterpriseEdition() {
954 t.Skip("EE only test, requires heartbeater error")
955 }
956 if !base.UnitTestUrlIsWalrus() {
957 t.Skip("LeakyBucketConfig not supported on CBS")
958 }
959
960 touchErr := errors.New("touch error")
961 rt := NewRestTester(t, &RestTesterConfig{
962 LeakyBucketConfig: &base.LeakyBucketConfig{
963 TouchCallback: func(key string) error {
964 if strings.Contains(key, "heartbeat_timeout") {
965 return touchErr
966 }
967 return nil
968 },
969 },
970 PersistentConfig: true,
971 })
972 defer rt.Close()
973
974 dbConfig := DatabaseConfig{
975 DbConfig: rt.NewDbConfig(),
976 }
977
978 // this call does use the leaky bucket
979 dbContext, err := rt.ServerContext().AddDatabaseFromConfigWithBucket(rt.Context(), t, dbConfig, rt.Bucket())
980 require.ErrorIs(t, err, touchErr)
981 require.Nil(t, dbContext)
982 require.Equal(t, "Offline", rt.GetDBState())
983
984 require.Equal(t, int64(1), rt.GetDatabase().DbStats.Database().TotalOnlineFatalErrors.Value())
985 require.Equal(t, int64(0), rt.GetDatabase().DbStats.Database().TotalInitFatalErrors.Value())
986 // assert that the db is reported with appropriate error state in all dbs
987 allDbs := rt.ServerContext().allDatabaseSummaries()
988 require.Len(t, allDbs, 1)
989 invalDb := allDbs[0]
990 require.NotNil(t, invalDb.DatabaseError)
991 assert.Equal(t, db.RunStateString[db.DBOffline], invalDb.State)
992 assert.Equal(t, invalDb.DatabaseError.ErrMsg, db.DatabaseErrorMap[db.DatabaseOnlineProcessError])
993
994 // assert that you can attempt again to bring db back online again after failure
995 resp := rt.SendAdminRequest(http.MethodPost, "/"+invalDb.Bucket+"/_online", "")
996 RequireStatus(t, resp, http.StatusOK)
997 rt.WaitForDBOnline()
998}
999
1000func TestDatabaseCollectionDeletedErrorState(t *testing.T) {
1001 if base.UnitTestUrlIsWalrus() {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
ServerContextMethod · 0.95
ContextMethod · 0.95
BucketMethod · 0.95
GetDBStateMethod · 0.95
GetDatabaseMethod · 0.95
SendAdminRequestMethod · 0.95
WaitForDBOnlineMethod · 0.95
IsEnterpriseEditionFunction · 0.92
UnitTestUrlIsWalrusFunction · 0.92
NewRestTesterFunction · 0.85

Tested by

no test coverage detected