@@ -598,172 +598,3 @@ func TestChannelCacheBackgroundTaskWithIllegalTimeInterval(t *testing.T) {
598598 assert .Equal (t , "CleanAgedItems" , backgroundTaskError .TaskName )
599599 assert .Equal (t , options .ChannelCacheAge , backgroundTaskError .Interval )
600600}
601-
602- // - The channel cache is validFrom sequence n, with one active mutation resident in the cache
603- // - There are channel removals (only) in the bucket with m < sequence < n
604- // - Client issues a GetChanges request with since=m
605- func TestChannelCacheActiveOnlyAndLimit (t * testing.T ) {
606- ctx , db , collection := setupDBWithChannelCacheSize (t , 2 )
607-
608- const (
609- activeChannel = "active"
610- inactiveChannel = "inactive"
611- doc1 = "doc1"
612- doc2 = "doc2"
613- doc3 = "doc3"
614- )
615-
616- // doc1 rev1: channel active
617- // doc1 rev2: channel inactive
618- // doc2 rev1: channel active
619- // doc2 rev2: channel inactive
620- // doc3 rev1: channel active
621- revID , _ , err := collection .Put (ctx , doc1 , Body {"channels" : activeChannel })
622- require .NoError (t , err )
623- _ , _ , err = collection .Put (ctx , doc1 , Body {"channels" : inactiveChannel , "_rev" : revID })
624- require .NoError (t , err )
625- revID , _ , err = collection .Put (ctx , doc2 , Body {"channels" : activeChannel })
626- require .NoError (t , err )
627- _ , _ , err = collection .Put (ctx , doc2 , Body {"channels" : inactiveChannel , "_rev" : revID })
628- require .NoError (t , err )
629-
630- _ , _ , err = collection .Put (ctx , doc3 , Body {"channels" : activeChannel })
631- require .NoError (t , err )
632-
633- db .WaitForPendingChanges (t )
634-
635- // prime channel cache, doc2 and doc3 should be in cache
636- changesOptions := ChangesOptions {
637- Since : SequenceID {Seq : 0 },
638- ActiveOnly : false ,
639- ChangesCtx : base .TestCtx (t ),
640- }
641- require .Len (t , getChanges (t , collection , base .SetOf (activeChannel ), changesOptions ), 3 )
642-
643- // whether limit or no limit, should only be 1 active entry
644- for _ , limit := range []int {0 , 1 } {
645- t .Run ("limit=" + fmt .Sprint (limit ), func (t * testing.T ) {
646- changesOptions = ChangesOptions {
647- Since : SequenceID {Seq : 0 },
648- ActiveOnly : true ,
649- ChangesCtx : base .TestCtx (t ),
650- Limit : limit ,
651- }
652- require .Len (t , getChanges (t , collection , base .SetOf (activeChannel ), changesOptions ), 1 )
653- })
654- }
655- }
656-
657- func TestChannelCacheActiveOnlyScenarios (t * testing.T ) {
658- const activeChannel = "active"
659-
660- t .Run ("query returns an active rev, cache is all removals" , func (t * testing.T ) {
661- ctx , db , collection := setupDBWithChannelCacheSize (t , 2 )
662-
663- // doc1: active (seq 1) - will be in backing store, not cache
664- _ , _ , _ = collection .Put (ctx , "doc1" , Body {"channels" : activeChannel })
665-
666- // doc2: active (seq 2) -> inactive (seq 3) - seq 3 in cache
667- revID2 , _ , _ := collection .Put (ctx , "doc2" , Body {"channels" : activeChannel })
668- _ , _ , _ = collection .Put (ctx , "doc2" , Body {"channels" : "other" , "_rev" : revID2 })
669-
670- // doc3: active (seq 4) -> inactive (seq 5) - seq 5 in cache
671- revID3 , _ , _ := collection .Put (ctx , "doc3" , Body {"channels" : activeChannel })
672- _ , _ , _ = collection .Put (ctx , "doc3" , Body {"channels" : "other" , "_rev" : revID3 })
673-
674- db .WaitForPendingChanges (t )
675-
676- // With limit 1 (before)
677- changesOptions := ChangesOptions {Since : SequenceID {Seq : 0 }, ActiveOnly : true , Limit : 1 , ChangesCtx : base .TestCtx (t )}
678- changes := getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
679- require .Len (t , changes , 1 )
680- assert .Equal (t , "doc1" , changes [0 ].ID )
681-
682- // No limit
683- changesOptions .Limit = 0
684- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
685- require .Len (t , changes , 1 )
686- assert .Equal (t , "doc1" , changes [0 ].ID )
687-
688- // With limit 1 (after)
689- changesOptions .Limit = 1
690- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
691- require .Len (t , changes , 1 )
692- assert .Equal (t , "doc1" , changes [0 ].ID )
693- })
694-
695- t .Run ("query returns an active rev, cache also has an active rev" , func (t * testing.T ) {
696- ctx , db , collection := setupDBWithChannelCacheSize (t , 2 )
697-
698- // doc1: active (seq 1) - backing store
699- _ , _ , _ = collection .Put (ctx , "doc1" , Body {"channels" : activeChannel })
700-
701- // doc2: active (seq 2) -> inactive (seq 3) - cache
702- revID2 , _ , _ := collection .Put (ctx , "doc2" , Body {"channels" : activeChannel })
703- _ , _ , _ = collection .Put (ctx , "doc2" , Body {"channels" : "other" , "_rev" : revID2 })
704-
705- // doc3: active (seq 4) - cache
706- _ , _ , _ = collection .Put (ctx , "doc3" , Body {"channels" : activeChannel })
707-
708- db .WaitForPendingChanges (t )
709-
710- // With limit 1 (before)
711- changesOptions := ChangesOptions {Since : SequenceID {Seq : 0 }, ActiveOnly : true , Limit : 1 , ChangesCtx : base .TestCtx (t )}
712- changes := getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
713- require .Len (t , changes , 1 )
714- assert .Equal (t , "doc1" , changes [0 ].ID )
715-
716- // No limit: should get doc1 and doc3
717- changesOptions .Limit = 0
718- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
719- require .Len (t , changes , 2 )
720- assert .Equal (t , "doc1" , changes [0 ].ID )
721- assert .Equal (t , "doc3" , changes [1 ].ID )
722-
723- // With limit 1 (after)
724- changesOptions .Limit = 1
725- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
726- require .Len (t , changes , 1 )
727- assert .Equal (t , "doc1" , changes [0 ].ID )
728- })
729-
730- t .Run ("query has no active revs, cache has no active revs" , func (t * testing.T ) {
731- ctx , db , collection := setupDBWithChannelCacheSize (t , 2 )
732-
733- // doc1: active (seq 1) -> inactive (seq 2)
734- revID1 , _ , _ := collection .Put (ctx , "doc1" , Body {"channels" : activeChannel })
735- _ , _ , _ = collection .Put (ctx , "doc1" , Body {"channels" : "other" , "_rev" : revID1 })
736-
737- // doc2: active (seq 3) -> inactive (seq 4)
738- revID2 , _ , _ := collection .Put (ctx , "doc2" , Body {"channels" : activeChannel })
739- _ , _ , _ = collection .Put (ctx , "doc2" , Body {"channels" : "other" , "_rev" : revID2 })
740-
741- db .WaitForPendingChanges (t )
742-
743- // With limit 1 (before)
744- changesOptions := ChangesOptions {Since : SequenceID {Seq : 0 }, ActiveOnly : true , Limit : 1 , ChangesCtx : base .TestCtx (t )}
745- changes := getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
746- require .Len (t , changes , 0 )
747-
748- // No limit: should get nothing
749- changesOptions .Limit = 0
750- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
751- require .Len (t , changes , 0 )
752-
753- // With limit 1 (after)
754- changesOptions .Limit = 1
755- changes = getChanges (t , collection , base .SetOf (activeChannel ), changesOptions )
756- require .Len (t , changes , 0 )
757- })
758- }
759-
760- func setupDBWithChannelCacheSize (t * testing.T , maxLength int ) (context.Context , * Database , * DatabaseCollectionWithUser ) {
761- cacheOptions := DefaultCacheOptions ()
762- cacheOptions .ChannelCacheMaxLength = maxLength
763- db , ctx := setupTestDBWithCacheOptions (t , cacheOptions )
764- t .Cleanup (func () { db .Close (ctx ) })
765- collection , ctx := GetSingleDatabaseCollectionWithUser (ctx , t , db )
766- _ , err := collection .UpdateSyncFun (ctx , channels .DocChannelsSyncFunction )
767- require .NoError (t , err )
768- return ctx , db , collection
769- }
0 commit comments