TestCollecitonStats ensures that stats are specific to each collection.
(t *testing.T)
| 761 | |
| 762 | // TestCollecitonStats ensures that stats are specific to each collection. |
| 763 | func 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()) |
nothing calls this directly
no test coverage detected