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

Function TestCollectionStats

rest/api_collections_test.go:763–890  ·  view source on GitHub ↗

TestCollecitonStats ensures that stats are specific to each collection.

(t *testing.T)

Source from the content-addressed store, hash-verified

761
762// TestCollecitonStats ensures that stats are specific to each collection.
763func TestCollectionStats(t *testing.T) {
764 base.TestRequiresCollections(t)
765
766 ctx := base.TestCtx(t)
767 tb := base.GetTestBucket(t)
768 defer tb.Close(ctx)
769
770 scopesConfig := GetCollectionsConfig(t, tb, 2)
771 dataStoreNames := GetDataStoreNamesFromScopesConfig(scopesConfig)
772 syncFn := `
773 function(doc) {
774 if (doc.throwException) {
775 channel(undefinedvariable);
776 }
777 if (doc.require) {
778 requireAdmin();
779 }
780 }`
781
782 scope1Name, collection1Name := dataStoreNames[0].ScopeName(), dataStoreNames[0].CollectionName()
783 scope2Name, collection2Name := dataStoreNames[1].ScopeName(), dataStoreNames[1].CollectionName()
784 scopesConfig[scope1Name].Collections[collection1Name] = &CollectionConfig{SyncFn: &syncFn}
785 scopesConfig[scope2Name].Collections[collection2Name] = &CollectionConfig{SyncFn: &syncFn}
786
787 rtConfig := &RestTesterConfig{
788 CustomTestBucket: tb,
789 GuestEnabled: true,
790 DatabaseConfig: &DatabaseConfig{
791 DbConfig: DbConfig{
792 Scopes: scopesConfig,
793 AutoImport: base.TestUseXattrs(),
794 EnableXattrs: base.Ptr(base.TestUseXattrs()),
795 },
796 },
797 }
798
799 rt := NewRestTesterMultipleCollections(t, rtConfig, 2)
800 defer rt.Close()
801
802 collection1Stats, err := rt.GetDatabase().DbStats.CollectionStat(scope1Name, collection1Name)
803 require.NoError(t, err)
804 assert.Equal(t, int64(0), collection1Stats.SyncFunctionCount.Value())
805 assert.Equal(t, int64(0), collection1Stats.SyncFunctionTime.Value())
806 assert.Equal(t, int64(0), collection1Stats.SyncFunctionRejectCount.Value())
807 assert.Equal(t, int64(0), collection1Stats.SyncFunctionRejectAccessCount.Value())
808 assert.Equal(t, int64(0), collection1Stats.SyncFunctionExceptionCount.Value())
809 assert.Equal(t, int64(0), collection1Stats.ImportCount.Value())
810 assert.Equal(t, int64(0), collection1Stats.NumDocReads.Value())
811 assert.Equal(t, int64(0), collection1Stats.DocReadsBytes.Value())
812 assert.Equal(t, int64(0), collection1Stats.NumDocWrites.Value())
813 assert.Equal(t, int64(0), collection1Stats.DocWritesBytes.Value())
814
815 collection2Stats, err := rt.GetDatabase().DbStats.CollectionStat(scope2Name, collection2Name)
816 require.NoError(t, err)
817 assert.Equal(t, int64(0), collection2Stats.SyncFunctionCount.Value())
818 assert.Equal(t, int64(0), collection2Stats.SyncFunctionTime.Value())
819 assert.Equal(t, int64(0), collection2Stats.SyncFunctionRejectCount.Value())
820 assert.Equal(t, int64(0), collection2Stats.SyncFunctionRejectAccessCount.Value())

Callers

nothing calls this directly

Calls 15

TestRequiresCollectionsFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
TestUseXattrsFunction · 0.92
PtrFunction · 0.92
RequireWaitForStatFunction · 0.92
GetCollectionsConfigFunction · 0.85
CollectionStatMethod · 0.80
SendAdminRequestMethod · 0.80
SendRequestMethod · 0.80

Tested by

no test coverage detected