From d0de79bffa4dc1de2a5f3054cfaa595ef174b36c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 31 May 2020 21:07:24 +0100 Subject: [PATCH] Trying to fix Travis-ci test units --- CliClient/tests/synchronizer.js | 14 +++++++------- CliClient/tests/test-utils.js | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CliClient/tests/synchronizer.js b/CliClient/tests/synchronizer.js index cc087e792..edcfec69d 100644 --- a/CliClient/tests/synchronizer.js +++ b/CliClient/tests/synchronizer.js @@ -3,7 +3,7 @@ require('app-module-path').addPath(__dirname); const { time } = require('lib/time-utils.js'); -const { setupDatabase, allSyncTargetItemsEncrypted, resourceFetcher, kvStore, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, checkThrowAsync, asyncTest } = require('test-utils.js'); +const { setupDatabase, allSyncTargetItemsEncrypted, tempFilePath, resourceFetcher, kvStore, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, checkThrowAsync, asyncTest } = require('test-utils.js'); const { shim } = require('lib/shim.js'); const fs = require('fs-extra'); const Folder = require('lib/models/Folder.js'); @@ -992,7 +992,7 @@ describe('synchronizer', function() { })); it('should sync resource blob changes', asyncTest(async () => { - const tempFile = `${__dirname}/tmp/test.txt`; + const tempFile = tempFilePath('txt'); await shim.fsDriver().writeFile(tempFile, '1234', 'utf8'); const folder1 = await Folder.save({ title: 'folder1' }); const note1 = await Note.save({ title: 'ma note', parent_id: folder1.id }); @@ -1005,7 +1005,7 @@ describe('synchronizer', function() { await resourceFetcher().start(); await resourceFetcher().waitForAllFinished(); let resource1_2 = (await Resource.all())[0]; - const modFile = `${__dirname}/tmp/test_mod.txt`; + const modFile = tempFilePath('txt'); await shim.fsDriver().writeFile(modFile, '1234 MOD', 'utf8'); await Resource.updateResourceBlobContent(resource1_2.id, modFile); const originalSize = resource1_2.size; @@ -1027,7 +1027,7 @@ describe('synchronizer', function() { it('should handle resource conflicts', asyncTest(async () => { { - const tempFile = `${__dirname}/tmp/test.txt`; + const tempFile = tempFilePath('txt'); await shim.fsDriver().writeFile(tempFile, '1234', 'utf8'); const folder1 = await Folder.save({ title: 'folder1' }); const note1 = await Note.save({ title: 'ma note', parent_id: folder1.id }); @@ -1042,7 +1042,7 @@ describe('synchronizer', function() { await resourceFetcher().start(); await resourceFetcher().waitForAllFinished(); const resource = (await Resource.all())[0]; - const modFile2 = `${__dirname}/tmp/test_mod_2.txt`; + const modFile2 = tempFilePath('txt'); await shim.fsDriver().writeFile(modFile2, '1234 MOD 2', 'utf8'); await Resource.updateResourceBlobContent(resource.id, modFile2); await synchronizer().start(); @@ -1053,7 +1053,7 @@ describe('synchronizer', function() { { // Going to modify a resource without syncing first, which will cause a conflict const resource = (await Resource.all())[0]; - const modFile1 = `${__dirname}/tmp/test_mod_1.txt`; + const modFile1 = tempFilePath('txt'); await shim.fsDriver().writeFile(modFile1, '1234 MOD 1', 'utf8'); await Resource.updateResourceBlobContent(resource.id, modFile1); await synchronizer().start(); // CONFLICT @@ -1087,7 +1087,7 @@ describe('synchronizer', function() { it('should handle resource conflicts if a resource is changed locally but deleted remotely', asyncTest(async () => { { - const tempFile = `${__dirname}/tmp/test.txt`; + const tempFile = tempFilePath('txt'); await shim.fsDriver().writeFile(tempFile, '1234', 'utf8'); const folder1 = await Folder.save({ title: 'folder1' }); const note1 = await Note.save({ title: 'ma note', parent_id: folder1.id }); diff --git a/CliClient/tests/test-utils.js b/CliClient/tests/test-utils.js index fbeda8c21..fcb12f2ed 100644 --- a/CliClient/tests/test-utils.js +++ b/CliClient/tests/test-utils.js @@ -41,6 +41,7 @@ const ResourceFetcher = require('lib/services/ResourceFetcher.js'); const KvStore = require('lib/services/KvStore.js'); const WebDavApi = require('lib/WebDavApi'); const DropboxApi = require('lib/DropboxApi'); +const md5 = require('md5'); const databases_ = []; const synchronizers_ = []; @@ -486,6 +487,10 @@ async function createNTestTags(n) { return tags; } +function tempFilePath(ext) { + return `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}.${ext}`; +} + // Application for feature integration testing class TestApp extends BaseApplication { constructor(hasGui = true) { @@ -554,4 +559,4 @@ class TestApp extends BaseApplication { } } -module.exports = { kvStore, resourceService, resourceFetcher, allSyncTargetItemsEncrypted, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, asyncTest, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp }; +module.exports = { kvStore, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, asyncTest, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp };