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

Function TestServerlessUpdateSuspendedDb

rest/serverless_test.go:476–521  ·  view source on GitHub ↗

Checks what happens to a suspended database when the config is modified by another node and the periodic fetchAndLoadConfigs gets called. Currently, it will be unsuspended however that behaviour may be changed in the future

(t *testing.T)

Source from the content-addressed store, hash-verified

474// Checks what happens to a suspended database when the config is modified by another node and the periodic fetchAndLoadConfigs gets called.
475// Currently, it will be unsuspended however that behaviour may be changed in the future
476func TestServerlessUpdateSuspendedDb(t *testing.T) {
477 RequireBucketSpecificCredentials(t)
478 ctx := base.TestCtx(t)
479 tb := base.GetTestBucket(t)
480 defer tb.Close(ctx)
481
482 rt := NewRestTester(t, &RestTesterConfig{
483 CustomTestBucket: tb.NoCloseClone(),
484 PersistentConfig: true,
485 MutateStartupConfig: func(config *StartupConfig) {
486 config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(0)
487 },
488 })
489 defer rt.Close()
490 sc := rt.ServerContext()
491
492 resp := rt.SendAdminRequest(http.MethodPut, "/db/",
493 fmt.Sprintf(
494 `{"bucket": "%s", "num_index_replicas": 0, "enable_shared_bucket_access": %t, "use_views": %t, "suspendable": true}`,
495 tb.GetName(), base.TestUseXattrs(), base.TestsDisableGSI(),
496 ),
497 )
498 RequireStatus(t, resp, http.StatusCreated)
499
500 // Suspend the database
501 assert.NoError(t, sc.suspendDatabase(t, rt.Context(), "db"))
502 // Update database config
503 newCas, err := sc.BootstrapContext.UpdateConfig(base.TestCtx(t), tb.GetName(), sc.Config.Bootstrap.ConfigGroupID, "db", func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) {
504 config := sc._dbConfigs["db"].ToDatabaseConfig()
505 config.cfgCas = bucketDbConfig.cfgCas
506 return config, nil
507 })
508 require.NoError(t, err)
509 // Confirm dbConfig cas did not update yet in SG, or get unsuspended
510 assert.NotEqual(t, sc._dbConfigs["db"].cfgCas, newCas)
511 assert.True(t, sc.isDatabaseSuspended(t, "db"))
512 assert.Nil(t, sc._databases["db"])
513 // Trigger update frequency (would usually happen every ConfigUpdateFrequency seconds)
514 count, err := sc.fetchAndLoadConfigs(rt.Context(), false)
515 require.NoError(t, err)
516 assert.Equal(t, 1, count)
517
518 // Make sure database is still suspended
519 assert.True(t, sc.isDatabaseSuspended(t, "db"))
520 assert.Nil(t, sc._databases["db"])
521}
522
523// Tests scenarios a database is and is not allowed to suspend
524func TestSuspendingFlags(t *testing.T) {

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
NewConfigDurationFunction · 0.92
TestUseXattrsFunction · 0.92
TestsDisableGSIFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85

Tested by

no test coverage detected