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

Function TestServerlessUnsuspendFetchFallback

rest/serverless_test.go:350–391  ·  view source on GitHub ↗

Confirms that when the database config is not in sc.dbConfigs, the fetch callback is check if the config is in a bucket

(t *testing.T)

Source from the content-addressed store, hash-verified

348
349// Confirms that when the database config is not in sc.dbConfigs, the fetch callback is check if the config is in a bucket
350func TestServerlessUnsuspendFetchFallback(t *testing.T) {
351 RequireBucketSpecificCredentials(t)
352 ctx := base.TestCtx(t)
353 tb := base.GetTestBucket(t)
354 defer tb.Close(ctx)
355
356 rt := NewRestTester(t, &RestTesterConfig{
357 CustomTestBucket: tb.NoCloseClone(),
358 serverless: true,
359 PersistentConfig: true,
360 MutateStartupConfig: func(config *StartupConfig) {
361 config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(0)
362 },
363 })
364 defer rt.Close()
365 sc := rt.ServerContext()
366
367 resp := rt.SendAdminRequest(http.MethodPut, "/db/",
368 fmt.Sprintf(
369 `{"bucket": "%s", "num_index_replicas": 0, "enable_shared_bucket_access": %t, "use_views": %t}`,
370 tb.GetName(), base.TestUseXattrs(), base.TestsDisableGSI(),
371 ),
372 )
373 RequireStatus(t, resp, http.StatusCreated)
374
375 // Suspend the database and remove it from dbConfigs, forcing unsuspendDatabase to fetch config from the bucket
376 err := sc.suspendDatabase(t, rt.Context(), "db")
377 assert.NoError(t, err)
378 delete(sc._dbConfigs, "db")
379 delete(sc._dbRegistry, "db")
380 assert.Nil(t, sc._databases["db"])
381
382 // Unsuspend db and confirm unsuspending worked
383 dbCtx, err := sc.GetDatabase(rt.Context(), "db")
384 assert.NoError(t, err)
385 assert.NotNil(t, dbCtx)
386 assert.NotNil(t, sc._databases["db"])
387
388 // Attempt to get invalid database
389 _, err = sc.GetDatabase(rt.Context(), "invalid")
390 assert.Contains(t, err.Error(), "no such database")
391}
392
393// Confirms that ServerContext.fetchConfigsWithTTL works correctly
394func TestServerlessFetchConfigsLimited(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