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

Function TestServerlessFetchConfigsLimited

rest/serverless_test.go:394–472  ·  view source on GitHub ↗

Confirms that ServerContext.fetchConfigsWithTTL works correctly

(t *testing.T)

Source from the content-addressed store, hash-verified

392
393// Confirms that ServerContext.fetchConfigsWithTTL works correctly
394func TestServerlessFetchConfigsLimited(t *testing.T) {
395 RequireBucketSpecificCredentials(t)
396
397 ctx := base.TestCtx(t)
398 tb := base.GetTestBucket(t)
399 defer tb.Close(ctx)
400
401 rt := NewRestTester(t, &RestTesterConfig{
402 CustomTestBucket: tb.NoCloseClone(),
403 PersistentConfig: true,
404 MutateStartupConfig: func(config *StartupConfig) {
405 config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(0)
406 },
407 })
408 defer rt.Close()
409 sc := rt.ServerContext()
410
411 resp := rt.SendAdminRequest(http.MethodPut, "/db/",
412 fmt.Sprintf(
413 `{"bucket": "%s", "num_index_replicas": 0, "enable_shared_bucket_access": %t, "use_views": %t}`,
414 tb.GetName(), base.TestUseXattrs(), base.TestsDisableGSI(),
415 ),
416 )
417 RequireStatus(t, resp, http.StatusCreated)
418
419 // Purposely make configs get caches
420 sc.Config.Unsupported.Serverless.MinConfigFetchInterval = base.NewConfigDuration(time.Hour)
421 dbConfigsBefore, err := sc.fetchConfigsSince(rt.Context(), sc.Config.Unsupported.Serverless.MinConfigFetchInterval)
422 require.NoError(t, err)
423 require.NotEmpty(t, dbConfigsBefore["db"])
424 timeCached := sc.fetchConfigsLastUpdate
425 require.NoError(t, err)
426 assert.NotZero(t, timeCached)
427
428 require.NoError(t, err)
429 // Update database config in the bucket (increment version)
430 newCas, err := sc.BootstrapContext.UpdateConfig(ctx, tb.GetName(), sc.Config.Bootstrap.ConfigGroupID, "db", func(bucketDbConfig *DatabaseConfig) (updatedConfig *DatabaseConfig, err error) {
431 bucketDbConfig.Version, err = GenerateDatabaseConfigVersionID(rt.Context(), bucketDbConfig.Version, &bucketDbConfig.DbConfig)
432 require.NoError(t, err)
433 return bucketDbConfig, nil
434 })
435 require.NoError(t, err)
436
437 // Fetch configs again and expect same config to be returned
438 dbConfigsAfter, err := sc.fetchConfigsSince(rt.Context(), sc.Config.Unsupported.Serverless.MinConfigFetchInterval)
439 require.NoError(t, err)
440 require.NotEmpty(t, dbConfigsAfter["db"])
441 assert.Equal(t, dbConfigsBefore["db"].cfgCas, dbConfigsAfter["db"].cfgCas)
442 assert.Equal(t, timeCached, sc.fetchConfigsLastUpdate)
443
444 // Make caching 1ms so it will grab newest config
445 sc.Config.Unsupported.Serverless.MinConfigFetchInterval = base.NewConfigDuration(time.Millisecond)
446 // Sleep to make sure enough time passes
447 time.Sleep(time.Millisecond * 500)
448 dbConfigsAfter, err = sc.fetchConfigsSince(rt.Context(), sc.Config.Unsupported.Serverless.MinConfigFetchInterval)
449 require.NoError(t, err)
450 require.NotEmpty(t, dbConfigsAfter["db"])
451 assert.Equal(t, newCas, dbConfigsAfter["db"].cfgCas)

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