Validate stats for view query
(t *testing.T)
| 25 | |
| 26 | // Validate stats for view query |
| 27 | func TestQueryChannelsStatsView(t *testing.T) { |
| 28 | |
| 29 | if !base.TestsDisableGSI() { |
| 30 | t.Skip("This test is view only, but GSI is enabled") |
| 31 | } |
| 32 | |
| 33 | db, ctx := setupTestDB(t) |
| 34 | defer db.Close(ctx) |
| 35 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 36 | |
| 37 | collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout) |
| 38 | |
| 39 | // docID -> Sequence |
| 40 | docSeqMap := make(map[string]uint64, 3) |
| 41 | |
| 42 | _, doc, err := collection.Put(ctx, "queryTestDoc1", Body{"channels": []string{"ABC"}}) |
| 43 | require.NoError(t, err, "Put queryDoc1") |
| 44 | docSeqMap["queryTestDoc1"] = doc.Sequence |
| 45 | _, doc, err = collection.Put(ctx, "queryTestDoc2", Body{"channels": []string{"ABC"}}) |
| 46 | require.NoError(t, err, "Put queryDoc2") |
| 47 | docSeqMap["queryTestDoc2"] = doc.Sequence |
| 48 | _, doc, err = collection.Put(ctx, "queryTestDoc3", Body{"channels": []string{"ABC"}}) |
| 49 | require.NoError(t, err, "Put queryDoc3") |
| 50 | docSeqMap["queryTestDoc3"] = doc.Sequence |
| 51 | |
| 52 | // Check expvar prior to test |
| 53 | queryExpvar := fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewChannels) |
| 54 | |
| 55 | channelQueryCountBefore := db.DbStats.Query(queryExpvar).QueryCount.Value() |
| 56 | channelQueryTimeBefore := db.DbStats.Query(queryExpvar).QueryTime.Value() |
| 57 | channelQueryErrorCountBefore := db.DbStats.Query(queryExpvar).QueryErrorCount.Value() |
| 58 | |
| 59 | // Issue channels query |
| 60 | results, queryErr := collection.QueryChannels(base.TestCtx(t), "ABC", docSeqMap["queryTestDoc1"], docSeqMap["queryTestDoc3"], 100, false) |
| 61 | assert.NoError(t, queryErr, "Query error") |
| 62 | |
| 63 | assert.Equal(t, 3, countQueryResults(ctx, results)) |
| 64 | |
| 65 | closeErr := results.Close() |
| 66 | assert.NoError(t, closeErr, "Close error") |
| 67 | |
| 68 | channelQueryCountAfter := db.DbStats.Query(queryExpvar).QueryCount.Value() |
| 69 | channelQueryTimeAfter := db.DbStats.Query(queryExpvar).QueryTime.Value() |
| 70 | channelQueryErrorCountAfter := db.DbStats.Query(queryExpvar).QueryErrorCount.Value() |
| 71 | |
| 72 | assert.Equal(t, channelQueryCountBefore+1, channelQueryCountAfter) |
| 73 | base.AssertTimestampGreaterThan(t, channelQueryTimeAfter, channelQueryTimeBefore, "Channel query time stat didn't change") |
| 74 | assert.Equal(t, channelQueryErrorCountBefore, channelQueryErrorCountAfter) |
| 75 | |
| 76 | } |
| 77 | |
| 78 | // Validate stats for n1ql query |
| 79 | func TestQueryChannelsStatsN1ql(t *testing.T) { |
nothing calls this directly
no test coverage detected