Validate stats for n1ql query
(t *testing.T)
| 77 | |
| 78 | // Validate stats for n1ql query |
| 79 | func TestQueryChannelsStatsN1ql(t *testing.T) { |
| 80 | |
| 81 | if base.TestsDisableGSI() { |
| 82 | t.Skip("This test is Couchbase Server only") |
| 83 | } |
| 84 | |
| 85 | db, ctx := setupTestDB(t) |
| 86 | defer db.Close(ctx) |
| 87 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 88 | |
| 89 | collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout) |
| 90 | |
| 91 | // docID -> Sequence |
| 92 | docSeqMap := make(map[string]uint64, 3) |
| 93 | |
| 94 | _, doc, err := collection.Put(ctx, "queryTestDoc1", Body{"channels": []string{"ABC"}}) |
| 95 | require.NoError(t, err, "Put queryDoc1") |
| 96 | docSeqMap["queryTestDoc1"] = doc.Sequence |
| 97 | _, doc, err = collection.Put(ctx, "queryTestDoc2", Body{"channels": []string{"ABC"}}) |
| 98 | require.NoError(t, err, "Put queryDoc2") |
| 99 | docSeqMap["queryTestDoc2"] = doc.Sequence |
| 100 | _, doc, err = collection.Put(ctx, "queryTestDoc3", Body{"channels": []string{"ABC"}}) |
| 101 | require.NoError(t, err, "Put queryDoc3") |
| 102 | docSeqMap["queryTestDoc3"] = doc.Sequence |
| 103 | |
| 104 | // Check expvar prior to test |
| 105 | channelQueryCountBefore := db.DbStats.Query(QueryTypeChannels).QueryCount.Value() |
| 106 | channelQueryTimeBefore := db.DbStats.Query(QueryTypeChannels).QueryTime.Value() |
| 107 | channelQueryErrorCountBefore := db.DbStats.Query(QueryTypeChannels).QueryErrorCount.Value() |
| 108 | |
| 109 | // Issue channels query |
| 110 | results, queryErr := collection.QueryChannels(base.TestCtx(t), "ABC", docSeqMap["queryTestDoc1"], docSeqMap["queryTestDoc3"], 100, false) |
| 111 | assert.NoError(t, queryErr, "Query error") |
| 112 | |
| 113 | assert.Equal(t, 3, countQueryResults(ctx, results)) |
| 114 | |
| 115 | closeErr := results.Close() |
| 116 | assert.NoError(t, closeErr, "Close error") |
| 117 | |
| 118 | channelQueryCountAfter := db.DbStats.Query(QueryTypeChannels).QueryCount.Value() |
| 119 | channelQueryTimeAfter := db.DbStats.Query(QueryTypeChannels).QueryTime.Value() |
| 120 | channelQueryErrorCountAfter := db.DbStats.Query(QueryTypeChannels).QueryErrorCount.Value() |
| 121 | |
| 122 | assert.Equal(t, channelQueryCountBefore+1, channelQueryCountAfter) |
| 123 | base.AssertTimestampGreaterThan(t, channelQueryTimeAfter, channelQueryTimeBefore, "Channel query time stat didn't change") |
| 124 | assert.Equal(t, channelQueryErrorCountBefore, channelQueryErrorCountAfter) |
| 125 | |
| 126 | } |
| 127 | |
| 128 | // Validate that channels queries (channels, starChannel) are covering |
| 129 | func TestCoveringQueries(t *testing.T) { |
nothing calls this directly
no test coverage detected