MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestChannelCacheBufferingWithUserDoc

Function TestChannelCacheBufferingWithUserDoc

db/change_cache_test.go:467–502  ·  view source on GitHub ↗

Test notification when buffered entries are processed after a user doc arrives.

(t *testing.T)

Source from the content-addressed store, hash-verified

465
466// Test notification when buffered entries are processed after a user doc arrives.
467func TestChannelCacheBufferingWithUserDoc(t *testing.T) {
468
469 base.SetUpTestLogging(t, base.LevelDebug, base.KeyCache, base.KeyChanges, base.KeyDCP)
470
471 db, ctx := setupTestDB(t)
472 defer db.Close(ctx)
473
474 collection := GetSingleDatabaseCollection(t, db.DatabaseContext)
475 collectionID := collection.GetCollectionID()
476
477 // Simulate seq 1 (user doc) being delayed - write 2 first
478 WriteDirect(t, collection, []string{"ABC"}, 2)
479
480 // Start wait for doc in ABC
481 chans := channels.SetOfNoValidate(
482 channels.NewID("ABC", collectionID))
483 waiter := db.mutationListener.NewWaiterWithChannels(chans, nil, false)
484
485 successChan := make(chan bool)
486 go func() {
487 waiter.Wait(ctx)
488 close(successChan)
489 }()
490
491 // Simulate a user doc update
492 writeUserDirect(t, db, "bernard", 1)
493
494 // Wait 3 seconds for notification, else fail the test.
495 select {
496 case <-successChan:
497 log.Println("notification successful")
498 case <-time.After(time.Second * 3):
499 t.Fatal("No notification after 3 seconds")
500 }
501
502}
503
504// Test backfill of late arriving sequences to the channel caches
505func TestChannelCacheBackfill(t *testing.T) {

Callers

nothing calls this directly

Calls 12

SetUpTestLoggingFunction · 0.92
SetOfNoValidateFunction · 0.92
NewIDFunction · 0.92
setupTestDBFunction · 0.85
WriteDirectFunction · 0.85
writeUserDirectFunction · 0.85
NewWaiterWithChannelsMethod · 0.80
AfterMethod · 0.80
CloseMethod · 0.65
GetCollectionIDMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected