(t *testing.T)
| 580 | } |
| 581 | |
| 582 | func TestChannelCacheStatsOnPrune(t *testing.T) { |
| 583 | |
| 584 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache) |
| 585 | |
| 586 | db, ctx := setupTestDB(t) |
| 587 | defer db.Close(ctx) |
| 588 | |
| 589 | stats, err := base.NewSyncGatewayStats() |
| 590 | require.NoError(t, err) |
| 591 | |
| 592 | dbstats, err := stats.NewDBStats("", false, false, false, nil, nil) |
| 593 | require.NoError(t, err) |
| 594 | |
| 595 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 596 | collectionID := collection.GetCollectionID() |
| 597 | |
| 598 | testStats := dbstats.Cache() |
| 599 | cache := newSingleChannelCache(collection, channels.NewID("Test1", collectionID), 0, testStats) |
| 600 | cache.options.ChannelCacheMaxLength = 5 |
| 601 | |
| 602 | // Add more than ChannelCacheMaxLength entries to cache |
| 603 | cache.addToCache(ctx, testLogEntry(1, "doc1", "1-a"), false) |
| 604 | cache.addToCache(ctx, testLogEntry(2, "doc2", "1-a"), true) |
| 605 | cache.addToCache(ctx, testLogEntry(3, "doc3", "1-a"), false) |
| 606 | cache.addToCache(ctx, testLogEntry(4, "doc4", "1-a"), true) |
| 607 | cache.addToCache(ctx, testLogEntry(5, "doc5", "1-a"), false) |
| 608 | cache.addToCache(ctx, testLogEntry(6, "doc6", "1-a"), true) |
| 609 | cache.addToCache(ctx, testLogEntry(7, "doc7", "1-a"), false) |
| 610 | cache.addToCache(ctx, testLogEntry(8, "doc8", "1-a"), true) |
| 611 | cache.addToCache(ctx, testLogEntry(9, "doc9", "1-a"), false) |
| 612 | cache.addToCache(ctx, testLogEntry(10, "doc10", "1-a"), true) |
| 613 | |
| 614 | active, tombstones, removals := getCacheUtilization(testStats) |
| 615 | assert.Equal(t, 2, active) |
| 616 | assert.Equal(t, 0, tombstones) |
| 617 | assert.Equal(t, 3, removals) |
| 618 | |
| 619 | } |
| 620 | |
| 621 | func TestChannelCacheStatsOnPrepend(t *testing.T) { |
| 622 |
nothing calls this directly
no test coverage detected