diff --git a/CliClient/app/fuzzing.js b/CliClient/app/fuzzing.js index ce23a016d..958e6bccc 100644 --- a/CliClient/app/fuzzing.js +++ b/CliClient/app/fuzzing.js @@ -3,12 +3,12 @@ require('babel-plugin-transform-runtime'); import { time } from 'lib/time-utils.js'; import { Logger } from 'lib/logger.js'; +import { dirname } from 'lib/path-utils.js'; import lodash from 'lodash'; - const exec = require('child_process').exec const fs = require('fs-extra'); -const baseDir = '/var/www/joplin/CliClient/tests/fuzzing'; +const baseDir = dirname(__dirname) + '/tests/fuzzing'; const syncDir = baseDir + '/sync'; const joplinAppPath = __dirname + '/main.js'; let syncDurations = []; @@ -85,13 +85,21 @@ function execCommand(client, command, options = {}) { }); } +async function clientItems(client) { + let itemsJson = await execCommand(client, 'dump'); + try { + return JSON.parse(itemsJson); + } catch (error) { + throw new Error('Cannot parse JSON: ' + itemsJson); + } +} + async function execRandomCommand(client) { let possibleCommands = [ ['mkbook {word}', 40], // CREATE FOLDER ['mknote {word}', 70], // CREATE NOTE [async () => { // DELETE RANDOM ITEM - let items = await execCommand(client, 'dump'); - items = JSON.parse(items); + let items = clientItems(client); let item = randomElement(items); if (!item) return; @@ -114,8 +122,7 @@ async function execRandomCommand(client) { return execCommand(client, 'sync --random-failures', options); }, 30], [async () => { // UPDATE RANDOM ITEM - let items = await execCommand(client, 'dump'); - items = JSON.parse(items); + let items = clientItems(client); let item = randomElement(items); if (!item) return; diff --git a/CliClient/fuzzing.sh b/CliClient/fuzzing.sh old mode 100644 new mode 100755 diff --git a/CliClient/tests/synchronizer.js b/CliClient/tests/synchronizer.js index 4776cf29c..9ffc036d8 100644 --- a/CliClient/tests/synchronizer.js +++ b/CliClient/tests/synchronizer.js @@ -425,7 +425,7 @@ describe('Synchronizer', function() { done(); }); - it('should allow duplicate folder title and rename the new one', async (done) => { + it('should allow duplicate folder titles', async (done) => { let localF1 = await Folder.save({ title: "folder" }); await switchClient(2); @@ -441,7 +441,7 @@ describe('Synchronizer', function() { let localF2 = await Folder.load(remoteF2.id); - expect(localF2.title == remoteF2.title).toBe(false); + expect(localF2.title == remoteF2.title).toBe(true); // Then that folder that has been renamed locally should be set in such a way // that synchronizing it applies the title change remotely, and that new title @@ -460,5 +460,5 @@ describe('Synchronizer', function() { done(); }); - + }); \ No newline at end of file diff --git a/CliClient/tests/test-utils.js b/CliClient/tests/test-utils.js index 98b2b8eb8..77823fccd 100644 --- a/CliClient/tests/test-utils.js +++ b/CliClient/tests/test-utils.js @@ -18,6 +18,7 @@ let currentClient_ = 1; const logger = new Logger(); logger.addTarget('file', { path: __dirname + '/data/log-test.txt' }); +//logger.addTarget('console'); logger.setLevel(Logger.LEVEL_DEBUG); function sleep(n) { diff --git a/lib/models/folder.js b/lib/models/folder.js index 2b6d37777..626679a6c 100644 --- a/lib/models/folder.js +++ b/lib/models/folder.js @@ -86,20 +86,12 @@ class Folder extends BaseItem { } static save(o, options = null) { - return Folder.loadByField('title', o.title).then((existingFolder) => { - if (existingFolder && existingFolder.id != o.id) { - let error = new Error(_('A notebook with title "%s" already exists', o.title)); - error.code = 'duplicateTitle'; - throw error; - } - - return super.save(o, options).then((folder) => { - this.dispatch({ - type: 'FOLDERS_UPDATE_ONE', - folder: folder, - }); - return folder; + return super.save(o, options).then((folder) => { + this.dispatch({ + type: 'FOLDERS_UPDATE_ONE', + folder: folder, }); + return folder; }); } diff --git a/lib/synchronizer.js b/lib/synchronizer.js index 0c5cedc19..319c1d0e5 100644 --- a/lib/synchronizer.js +++ b/lib/synchronizer.js @@ -319,20 +319,7 @@ class Synchronizer { await Resource.setContent(newContent, remoteResourceContent); } - try { - await ItemClass.save(newContent, options); - } catch (error) { - - if (this.randomFailure(options, 3)) return; - - if (error.code == 'duplicateTitle') { - newContent.title = newContent.title + '-' + newContent.created_time + '-' + (Math.floor(Math.random() * 1000)); - newContent.updated_time = newContent.sync_time + 2; - await ItemClass.save(newContent, options); - } else { - throw error; - } - } + await ItemClass.save(newContent, options); if (newContent.type_ == BaseModel.MODEL_TYPE_TAG) { let noteIds = newContent.notes_.split(',');