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

Function TestServerlessSuspendDatabase

rest/serverless_test.go:274–347  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

272}
273
274func TestServerlessSuspendDatabase(t *testing.T) {
275 RequireBucketSpecificCredentials(t)
276
277 ctx := base.TestCtx(t)
278 // Get test bucket
279 tb := base.GetTestBucket(t)
280 defer tb.Close(ctx)
281
282 rt := NewRestTester(t, &RestTesterConfig{CustomTestBucket: tb.NoCloseClone(), PersistentConfig: true, serverless: true})
283 defer rt.Close()
284
285 sc := rt.ServerContext()
286
287 // suspendable should default to true when in serverless
288 resp := rt.SendAdminRequest(http.MethodPut, "/db/", fmt.Sprintf(`{
289 "bucket": "%s",
290 "use_views": %t,
291 "num_index_replicas": 0
292 }`, tb.GetName(), base.TestsDisableGSI()))
293 RequireStatus(t, resp, http.StatusCreated)
294
295 assert.False(t, sc.isDatabaseSuspended(t, "db"))
296 assert.NotNil(t, sc._databases["db"])
297 assert.NotNil(t, sc._dbRegistry["db"])
298 assert.NotNil(t, sc._dbConfigs["db"])
299
300 // Unsuspend db that is not suspended should just return db context
301 dbCtx, err := sc.unsuspendDatabase(rt.Context(), "db")
302 assert.NotNil(t, dbCtx)
303 assert.NoError(t, err)
304
305 // Confirm false returned when db does not exist
306 err = sc.suspendDatabase(t, rt.Context(), "invalid_db")
307 assert.ErrorIs(t, base.ErrNotFound, err)
308
309 // Confirm true returned when suspended a database successfully
310 err = sc.suspendDatabase(t, rt.Context(), "db")
311 assert.NoError(t, err)
312
313 // Make sure database is suspended
314 assert.True(t, sc.isDatabaseSuspended(t, "db"))
315 assert.Nil(t, sc._databases["db"])
316 assert.NotNil(t, sc._dbRegistry["db"])
317 assert.NotNil(t, sc._dbConfigs["db"])
318
319 // Update config in bucket to see if unsuspending check for updates
320 sc._dbConfigs["db"].EnableXattrs = base.Ptr(true) // xattrs must be enabled
321 cas, err := sc.BootstrapContext.UpdateConfig(base.TestCtx(t), tb.GetName(), sc.Config.Bootstrap.ConfigGroupID, "db", func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) {
322 config := sc._dbConfigs["db"].ToDatabaseConfig()
323 config.cfgCas = bucketDbConfig.cfgCas
324 return config, nil
325 })
326 require.NoError(t, err)
327 assert.NotEqual(t, cas, sc._dbConfigs["db"].cfgCas)
328
329 // Unsuspend db
330 dbCtx, err = sc.unsuspendDatabase(rt.Context(), "db")
331 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ServerContextMethod · 0.95
SendAdminRequestMethod · 0.95
ContextMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
TestsDisableGSIFunction · 0.92
PtrFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
NoCloseCloneMethod · 0.80

Tested by

no test coverage detected