Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,15 @@ class Sync {

return new Promise((resolve, reject) => {
let feedObserver
let onWillStop
const done = (result, err) => {
if (feedObserver) feedObserver.cancel()
this.lifecycle.off('will-stop', done)
if (onWillStop) this.lifecycle.off('will-stop', onWillStop)
if (err) reject(err)
else resolve(result)
}
this.lifecycle.once('will-stop', () => done(false))
onWillStop = () => done(false)
this.lifecycle.once('will-stop', onWillStop)

feedObserver = this.pouch.db
.changes(opts)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe('Add', () => {
})

context('and the directory is updated after its content is added', () => {
it('creates the directory and its content on the remote Cozy without errors', async () => {
it('creates the directory and its content on the remote Cozy without errors', async function() {
// Create directory and its content
const dir = await createDoc('local', 'dir', parent)
const subdir = await createDoc('local', 'subdir', dir)
Expand Down
11 changes: 5 additions & 6 deletions test/integration/differential_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,15 @@ describe('Differential synchronization', () => {
// `Photos/My Image.png` too many times and ends up recreating its
// missing parent (i.e. `Photos/`), thus triggering an uncaught
// `ExcludedDir` error.
const localScanDone = async () => {
await new Promise(resolve => {
helpers.local.side.events.on('local-end', resolve)
const waitForLocalEnd = () =>
new Promise(resolve => {
helpers.local.side.events.once('local-end', resolve)
})
}
await helpers.local.side.start()
await localScanDone()
const localChangesDone = waitForLocalEnd()
await helpers.local.syncDir.ensureDir('Photos')
await helpers.local.syncDir.ensureFile('Photos/My Image.png')
await localScanDone()
await localChangesDone
await helpers.syncAll()

should(await helpers.local.treeWithoutTrash()).deepEqual([
Expand Down
24 changes: 20 additions & 4 deletions test/integration/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const _ = require('lodash')
const should = require('should')

const { TRASH_DIR_ID } = require('../../core/remote/constants')
const { MAX_SYNC_RETRIES } = require('../../core/sync')
const { logger } = require('../../core/utils/logger')
const Builders = require('../support/builders')
const dbBuilders = require('../support/builders/db')
Expand Down Expand Up @@ -1158,6 +1159,19 @@ describe('Move', () => {
await helpers.local.syncDir.move('dir', 'renamed')
await helpers.local.scan()
}
const exhaustMissingDocumentRetries = async dirPath => {
const docs = [
await helpers.docByPath(dirPath),
...(await pouch.byRecursivePath(dirPath))
]

await pouch.bulkDocs(
docs.map(doc => ({
...doc,
errors: MAX_SYNC_RETRIES - 1
}))
)
}

context('overwritting existing remote directory', () => {
let existing, overwritten
Expand Down Expand Up @@ -1218,10 +1232,11 @@ describe('Move', () => {
await helpers.remote.ignorePreviousChanges()
})

// We should be retrying a few times and then finally skip the change to
// avoid looping over it.
// Start from exhausted retries to validate the recovery without waiting
// for every auto-retry in this integration test.
it('ends up replacing the overwritten file', async () => {
await moveDir()
await exhaustMissingDocumentRetries('renamed')
await helpers.syncAll()

should(await helpers.trees()).deepEqual({
Expand Down Expand Up @@ -1260,10 +1275,11 @@ describe('Move', () => {
await helpers.remote.ignorePreviousChanges()
})

// We should be retrying a few times and then finally skip the change to
// avoid looping over it.
// Start from exhausted retries to validate the recovery without waiting
// for every auto-retry in this integration test.
it('ends up re-uploading the file at the destination', async () => {
await moveDir()
await exhaustMissingDocumentRetries('renamed')
await helpers.syncAll()

should(await helpers.trees()).deepEqual({
Expand Down
13 changes: 13 additions & 0 deletions test/unit/sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ describe('Sync', function() {
builders = new Builders(this)
})

describe('hasChangesToSync', () => {
it('removes its stop listener once it resolves', async function() {
await builders
.metafile()
.path('file')
.sides({ local: 1 })
.create()

should(await this.sync.hasChangesToSync()).be.true()
should(this.sync.lifecycle.listenerCount('will-stop')).eql(0)
})
})

describe('start', function() {
beforeEach('instanciate sync', function() {
const events = new EventEmitter()
Expand Down
Loading