Skip to content

Commit eb28213

Browse files
committed
add e2e tests
1 parent fc32295 commit eb28213

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

packages/services/src/Domain/Application/ApplicationInterface.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
MfaServiceInterface,
1414
GenerateUuid,
1515
CreateDecryptedBackupFile,
16+
SyncBackoffServiceInterface,
1617
} from '@standardnotes/services'
1718
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
1819
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
@@ -100,6 +101,7 @@ export interface ApplicationInterface {
100101
get storage(): StorageServiceInterface
101102
get subscriptions(): SubscriptionManagerInterface
102103
get sync(): SyncServiceInterface
104+
get syncBackoff(): SyncBackoffServiceInterface
103105
get user(): UserServiceInterface
104106
get vaultInvites(): VaultInviteServiceInterface
105107
get vaultLocks(): VaultLockServiceInterface

packages/snjs/lib/Application/Application.ts

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
CreateDecryptedBackupFile,
8282
CreateEncryptedBackupFile,
8383
WebSocketsService,
84+
SyncBackoffServiceInterface,
8485
} from '@standardnotes/services'
8586
import {
8687
SNNote,
@@ -1016,6 +1017,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
10161017
return this.dependencies.get<SyncServiceInterface>(TYPES.SyncService)
10171018
}
10181019

1020+
public get syncBackoff(): SyncBackoffServiceInterface {
1021+
return this.dependencies.get<SyncBackoffServiceInterface>(TYPES.SyncBackoffService)
1022+
}
1023+
10191024
public get user(): UserServiceInterface {
10201025
return this.dependencies.get<UserServiceInterface>(TYPES.UserService)
10211026
}

packages/snjs/mocha/lib/AppContext.js

+8
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ export class AppContext {
593593
return note
594594
}
595595

596+
async createUnsyncedNote(title = 'foo', text = 'bar') {
597+
const payload = createNotePayload(title, text)
598+
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
599+
await this.application.mutator.setItemDirty(item)
600+
601+
return item
602+
}
603+
596604
lockSyncing() {
597605
this.application.sync.lockSyncing()
598606
}

packages/snjs/mocha/sync_tests/online.test.js

+63
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,69 @@ describe('online syncing', function () {
627627
await secondContext.deinit()
628628
}).timeout(Factory.SixtySecondTimeout)
629629

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+
630693
it('syncing an item should storage it encrypted', async function () {
631694
const note = await Factory.createMappedNote(application)
632695
await application.mutator.setItemDirty(note)

0 commit comments

Comments
 (0)