Test that housekeeping goroutines get terminated when change cache is stopped
(t *testing.T)
| 1122 | |
| 1123 | // Test that housekeeping goroutines get terminated when change cache is stopped |
| 1124 | func TestStopChangeCache(t *testing.T) { |
| 1125 | |
| 1126 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyChanges, base.KeyDCP) |
| 1127 | |
| 1128 | // Setup short-wait cache to ensure cleanup goroutines fire often |
| 1129 | cacheOptions := DefaultCacheOptions() |
| 1130 | cacheOptions.CachePendingSeqMaxWait = 10 * time.Millisecond |
| 1131 | cacheOptions.CachePendingSeqMaxNum = 50 |
| 1132 | cacheOptions.CacheSkippedSeqMaxWait = 1 * time.Second |
| 1133 | |
| 1134 | // Use leaky bucket to have the tap feed 'lose' document 3 |
| 1135 | leakyConfig := base.LeakyBucketConfig{ |
| 1136 | DCPFeedMissingDocs: []string{"doc-3"}, |
| 1137 | } |
| 1138 | db, ctx := setupTestLeakyDBWithCacheOptions(t, cacheOptions, leakyConfig) |
| 1139 | |
| 1140 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 1141 | // Write sequences direct |
| 1142 | WriteDirect(t, collection, []string{"ABC"}, 1) |
| 1143 | WriteDirect(t, collection, []string{"ABC"}, 2) |
| 1144 | WriteDirect(t, collection, []string{"ABC"}, 3) |
| 1145 | |
| 1146 | // Artificially add 3 skipped, and back date skipped entry by 2 hours to trigger attempted view retrieval during Clean call |
| 1147 | err := db.changeCache.skippedSeqs.PushSkippedSequenceEntry(NewSingleSkippedSequenceEntryAt(3, time.Now().Unix()-7200)) |
| 1148 | require.NoError(t, err) |
| 1149 | |
| 1150 | // tear down the DB. Should stop the cache before view retrieval of the skipped sequence is attempted. |
| 1151 | db.Close(ctx) |
| 1152 | |
| 1153 | // Hang around a while to see if the housekeeping tasks fire and panic |
| 1154 | time.Sleep(1 * time.Second) |
| 1155 | |
| 1156 | } |
| 1157 | |
| 1158 | // Test size config |
| 1159 | func TestChannelCacheSize(t *testing.T) { |
nothing calls this directly
no test coverage detected