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

Function TestOfflineDatabaseStartup

rest/server_context_test.go:818–863  ·  view source on GitHub ↗

TestOfflineDatabaseStartup ensures that background processes are not actually running when starting up a database in offline mode.

(t *testing.T)

Source from the content-addressed store, hash-verified

816
817// TestOfflineDatabaseStartup ensures that background processes are not actually running when starting up a database in offline mode.
818func TestOfflineDatabaseStartup(t *testing.T) {
819 if !base.TestUseXattrs() {
820 t.Skip("TestOfflineDatabaseStartup requires xattrs for document import")
821 }
822
823 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
824
825 rt := NewRestTester(t, &RestTesterConfig{
826 DatabaseConfig: &DatabaseConfig{
827 DbConfig: DbConfig{
828 StartOffline: base.Ptr(true),
829 AutoImport: true,
830 EnableXattrs: base.Ptr(true),
831 },
832 },
833 })
834 defer rt.Close()
835
836 ds := rt.GetSingleDataStore()
837 _, err := ds.AddRaw("doc1", 0, []byte(`{"type":"doc1"}`))
838 require.NoError(t, err)
839
840 // make sure we actually started offline (try to put a doc through the REST API)
841 resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/doc2", `{"type":"doc2"}`)
842 RequireStatus(t, resp, http.StatusServiceUnavailable)
843
844 // put doc2 bypassing offline checks (this step will begin to fail with Elixir - since we're making offline more comprehensive)
845 collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser()
846 _, _, err = collection.Put(ctx, "doc2", db.Body{"type": "doc2"})
847 require.NoError(t, err)
848
849 require.Nil(t, rt.GetDatabase().ImportListener)
850
851 // ensure doc1 is not imported - since we started the database offline
852 assert.Equal(t, int64(0), rt.GetDatabase().DbStats.SharedBucketImport().ImportCount.Value())
853
854 rt.ServerContext().TakeDbOnline(base.NewNonCancelCtx(), rt.GetDatabase())
855 require.NotNil(t, rt.GetDatabase().ImportListener)
856
857 resp = rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/doc3", `{"type":"doc3"}`)
858 RequireStatus(t, resp, http.StatusCreated)
859
860 // ensure doc1 is imported now we're online
861 rt.WaitForChanges(3, "/{{.keyspace}}/_changes", "", true)
862 assert.Equal(t, int64(1), rt.GetDatabase().DbStats.SharedBucketImport().ImportCount.Value())
863}
864
865func TestCompactIntervalFromConfig(t *testing.T) {
866 testCases := []struct {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
SendAdminRequestMethod · 0.95
GetDatabaseMethod · 0.95
ServerContextMethod · 0.95
WaitForChangesMethod · 0.95
TestUseXattrsFunction · 0.92
SetUpTestLoggingFunction · 0.92
PtrFunction · 0.92
NewNonCancelCtxFunction · 0.92
NewRestTesterFunction · 0.85

Tested by

no test coverage detected