@@ -627,6 +627,69 @@ describe('online syncing', function () {
627
627
await secondContext . deinit ( )
628
628
} ) . timeout ( Factory . SixtySecondTimeout )
629
629
630
+ it ( 'should eventually sync notes that are backed off for a penalty time because of creating too large of a payload' , async function ( ) {
631
+ const response = await fetch ( '/mocha/assets/small_file.md' )
632
+ const buffer = new Uint8Array ( await response . arrayBuffer ( ) )
633
+ const contents = buffer . toString ( )
634
+ const numberOfNotesToExceedThe1MBPayloadLimit = Math . ceil ( 100_000 / buffer . length ) + 1
635
+
636
+ expect ( application . items . getDirtyItems ( ) . length ) . to . equal ( 0 )
637
+
638
+ for ( let i = 0 ; i < numberOfNotesToExceedThe1MBPayloadLimit ; i ++ ) {
639
+ await context . createUnsyncedNote ( `note ${ i } ` , contents )
640
+ expectedItemCount ++
641
+ }
642
+ await context . sync ( )
643
+
644
+ expect ( application . items . getDirtyItems ( ) . length ) . to . equal ( numberOfNotesToExceedThe1MBPayloadLimit )
645
+
646
+ while ( application . items . getDirtyItems ( ) . length > 0 ) {
647
+ application . items . getDirtyItems ( ) . length
648
+
649
+ await context . sync ( )
650
+
651
+ await Factory . sleep ( 1 )
652
+ }
653
+
654
+ expect ( application . items . getDirtyItems ( ) . length ) . to . equal ( 0 )
655
+ } ) . timeout ( Factory . TwentySecondTimeout )
656
+
657
+ it ( 'should not sync notes that solely create a too large payload and are backed off for a penalty time' , async function ( ) {
658
+ const response = await fetch ( '/mocha/assets/small_file.md' )
659
+ const buffer = new Uint8Array ( await response . arrayBuffer ( ) )
660
+ const contents = buffer . toString ( )
661
+ const numberOfNotesToExceedThe1MBPayloadLimit = Math . ceil ( 100_000 / buffer . length ) + 1
662
+
663
+ expect ( application . items . getDirtyItems ( ) . length ) . to . equal ( 0 )
664
+
665
+ let hugeContents = ''
666
+ for ( let i = 0 ; i < numberOfNotesToExceedThe1MBPayloadLimit ; i ++ ) {
667
+ hugeContents += contents
668
+ }
669
+ const hugeNote = await context . createUnsyncedNote ( `Huge note that never should be synced` , hugeContents )
670
+ expectedItemCount ++
671
+ const smallNote = await context . createUnsyncedNote ( `Small note that should be synced` , 'Small note that should be synced' )
672
+ expectedItemCount ++
673
+
674
+ await context . sync ( )
675
+
676
+ expect ( application . items . getDirtyItems ( ) . length ) . to . equal ( 2 )
677
+
678
+ while ( application . items . getDirtyItems ( ) . length > 1 ) {
679
+ await Factory . sleep ( 1 )
680
+
681
+ application . items . getDirtyItems ( ) . length
682
+
683
+ await context . sync ( )
684
+ }
685
+
686
+ expect ( application . syncBackoff . isItemInBackoff ( smallNote ) ) . to . equal ( false )
687
+ expect ( application . syncBackoff . isItemInBackoff ( hugeNote ) ) . to . equal ( true )
688
+
689
+ const hugeNoteIsNotConsideredForAPotentialCandidateForNextSync = application . syncBackoff . getSmallerSubsetOfItemUuidsInBackoff ( ) . length === 0
690
+ expect ( hugeNoteIsNotConsideredForAPotentialCandidateForNextSync ) . to . equal ( true )
691
+ } ) . timeout ( Factory . TwentySecondTimeout )
692
+
630
693
it ( 'syncing an item should storage it encrypted' , async function ( ) {
631
694
const note = await Factory . createMappedNote ( application )
632
695
await application . mutator . setItemDirty ( note )
0 commit comments