Skip to content

Commit b41b934

Browse files
committed
test(sync): Making changes to the tree while syncing should not cause trouble
see #1857 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 742bf34 commit b41b934

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

src/test/test.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,151 @@ describe('Floccus', function() {
30203020
true
30213021
)
30223022
})
3023+
it('should not be confused by changes while syncing', async function() {
3024+
if (ACCOUNT_DATA.noCache) {
3025+
return this.skip()
3026+
}
3027+
3028+
const localRoot = account.getData().localRoot
3029+
const fooFolder = await browser.bookmarks.create({
3030+
title: 'foo',
3031+
parentId: localRoot
3032+
})
3033+
const barFolder = await browser.bookmarks.create({
3034+
title: 'bar',
3035+
parentId: fooFolder.id
3036+
})
3037+
const bookmark = await browser.bookmarks.create({
3038+
title: 'url',
3039+
url: 'http://ur.l/',
3040+
parentId: barFolder.id
3041+
})
3042+
3043+
await account.sync() // propagate to server
3044+
expect(account.getData().error).to.not.be.ok
3045+
3046+
const bookmark2 = await browser.bookmarks.create({
3047+
title: 'url2',
3048+
url: 'http://ur2.l/',
3049+
parentId: barFolder.id
3050+
})
3051+
3052+
// Make changes while sync is happening
3053+
let bookmark3
3054+
const getBookmarksTree = account.localTree.getBookmarksTree
3055+
account.localTree.getBookmarksTree = async() => {
3056+
const result = await getBookmarksTree.call(account.localTree)
3057+
console.log('CHANGING TREE NOW WHILE SYNCING')
3058+
await browser.bookmarks.remove(bookmark2.id)
3059+
bookmark3 = await browser.bookmarks.create({
3060+
title: 'url3',
3061+
url: 'http://ur3.l/',
3062+
parentId: barFolder.id
3063+
})
3064+
account.localTree.getBookmarksTree = getBookmarksTree
3065+
return result
3066+
}
3067+
await account.sync()
3068+
3069+
expect(account.getData().error).to.not.be.ok
3070+
3071+
const tree = await getAllBookmarks(account)
3072+
expectTreeEqual(
3073+
tree,
3074+
new Folder({
3075+
title: tree.title,
3076+
children: [
3077+
new Folder({
3078+
title: 'foo',
3079+
children: [
3080+
new Folder({
3081+
title: 'bar',
3082+
children: [
3083+
new Bookmark({
3084+
title: bookmark.title,
3085+
url: bookmark.url
3086+
}),
3087+
new Bookmark({
3088+
title: bookmark2.title,
3089+
url: bookmark2.url
3090+
}),
3091+
]
3092+
})
3093+
]
3094+
})
3095+
]
3096+
}),
3097+
false
3098+
)
3099+
const localTree = await account.localTree.getBookmarksTree(true)
3100+
expectTreeEqual(
3101+
localTree,
3102+
new Folder({
3103+
title: localTree.title,
3104+
children: [
3105+
new Folder({
3106+
title: 'foo',
3107+
children: [
3108+
new Folder({
3109+
title: 'bar',
3110+
children: [
3111+
new Bookmark({
3112+
title: bookmark.title,
3113+
url: bookmark.url
3114+
}),
3115+
new Bookmark({
3116+
title: bookmark3.title,
3117+
url: bookmark3.url
3118+
}),
3119+
]
3120+
})
3121+
]
3122+
})
3123+
]
3124+
}),
3125+
false
3126+
)
3127+
3128+
// Sync again to check if bookmark 3 gets picked
3129+
await account.sync()
3130+
expect(account.getData().error).to.not.be.ok
3131+
3132+
const tree2 = await getAllBookmarks(account)
3133+
expectTreeEqual(
3134+
tree2,
3135+
new Folder({
3136+
title: tree2.title,
3137+
children: [
3138+
new Folder({
3139+
title: 'foo',
3140+
children: [
3141+
new Folder({
3142+
title: 'bar',
3143+
children: [
3144+
new Bookmark({
3145+
title: bookmark.title,
3146+
url: bookmark.url
3147+
}),
3148+
new Bookmark({
3149+
title: bookmark3.title,
3150+
url: bookmark3.url
3151+
}),
3152+
]
3153+
})
3154+
]
3155+
})
3156+
]
3157+
}),
3158+
false
3159+
)
3160+
const localTree2 = await account.localTree.getBookmarksTree(true)
3161+
localTree2.title = tree2.title
3162+
expectTreeEqual(
3163+
localTree2,
3164+
tree2,
3165+
false
3166+
)
3167+
})
30233168
context('with slave mode', function() {
30243169
it("shouldn't create local bookmarks on the server", async function() {
30253170
await account.setData({ strategy: 'slave' })

0 commit comments

Comments
 (0)