TestOfflineDatabaseStartup ensures that background processes are not actually running when starting up a database in offline mode.
(t *testing.T)
| 816 | |
| 817 | // TestOfflineDatabaseStartup ensures that background processes are not actually running when starting up a database in offline mode. |
| 818 | func 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 | |
| 865 | func TestCompactIntervalFromConfig(t *testing.T) { |
| 866 | testCases := []struct { |
nothing calls this directly
no test coverage detected