TestJumpInSequencesAtAllocatorRangeInPending: - High level test - Add a doc through Sync Gateway - Alter that allocated sequence to be higher value. Mocking this document arriving from different env (e.g. via XDCR) - Wait for this sequence to arrive over cache feed and subsequently pushed to pending
(t *testing.T)
| 334 | // - Update this doc again, triggering unused sequence range release |
| 335 | // - Write another doc and assert that the changes feed returns all expected docs |
| 336 | func TestJumpInSequencesAtAllocatorRangeInPending(t *testing.T) { |
| 337 | if !base.TestUseXattrs() { |
| 338 | t.Skip("This test requires xattrs because it writes directly to the xattr") |
| 339 | } |
| 340 | |
| 341 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 342 | |
| 343 | rt := NewRestTester(t, &RestTesterConfig{ |
| 344 | DatabaseConfig: &DatabaseConfig{DbConfig: DbConfig{ |
| 345 | AutoImport: false, |
| 346 | CacheConfig: &CacheConfig{ |
| 347 | ChannelCacheConfig: &ChannelCacheConfig{ |
| 348 | MaxWaitPending: base.Ptr(uint32(1500)), |
| 349 | }, |
| 350 | }, |
| 351 | }}, |
| 352 | }) |
| 353 | defer rt.Close() |
| 354 | ctx := base.TestCtx(t) |
| 355 | |
| 356 | vrs := rt.PutDoc("doc", `{"prop":true}`) |
| 357 | |
| 358 | resp := rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/_changes", "") |
| 359 | RequireStatus(t, resp, http.StatusOK) |
| 360 | |
| 361 | ds := rt.GetSingleDataStore() |
| 362 | xattrs, cas, err := ds.GetXattrs(ctx, "doc", []string{base.SyncXattrName}) |
| 363 | require.NoError(t, err) |
| 364 | |
| 365 | var retrievedXattr map[string]interface{} |
| 366 | require.NoError(t, base.JSONUnmarshal(xattrs[base.SyncXattrName], &retrievedXattr)) |
| 367 | retrievedXattr["sequence"] = uint64(20) |
| 368 | newXattrVal := map[string][]byte{ |
| 369 | base.SyncXattrName: base.MustJSONMarshal(t, retrievedXattr), |
| 370 | } |
| 371 | |
| 372 | _, err = ds.UpdateXattrs(ctx, "doc", 0, cas, newXattrVal, nil) |
| 373 | require.NoError(t, err) |
| 374 | |
| 375 | // wait for value top be added to pending |
| 376 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 377 | rt.GetDatabase().UpdateCalculatedStats(ctx) |
| 378 | assert.Equal(c, int64(1), rt.GetDatabase().DbStats.CacheStats.PendingSeqLen.Value()) |
| 379 | }, time.Second*10, time.Millisecond*100) |
| 380 | |
| 381 | docVrs := rt.UpdateDoc("doc", vrs, `{"prob": "lol"}`) |
| 382 | |
| 383 | // assert that nothing has been pushed to skipped |
| 384 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 385 | rt.GetDatabase().UpdateCalculatedStats(ctx) |
| 386 | assert.Equal(c, int64(0), rt.GetDatabase().DbStats.CacheStats.NumCurrentSeqsSkipped.Value()) |
| 387 | assert.Equal(c, int64(0), rt.GetDatabase().DbStats.CacheStats.SkippedSequenceSkiplistNodes.Value()) |
| 388 | }, time.Second*10, time.Millisecond*100) |
| 389 | |
| 390 | doc1Vrs := rt.PutDoc("doc1", `{"prop":true}`) |
| 391 | |
| 392 | changes := rt.WaitForChanges(2, "/{{.keyspace}}/_changes", "", true) |
| 393 | changes.RequireDocIDs(t, []string{"doc1", "doc"}) |
nothing calls this directly
no test coverage detected