From 409a9414f187e931575074965e68bcbe1761fc2a Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 27 Jun 2017 02:07:03 +0200 Subject: [PATCH] fix the "gc state" warning --- src/Connector.js | 6 ++++-- src/Database.js | 3 ++- tests-lib/helper.js | 30 ++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Connector.js b/src/Connector.js index 3ad0f68e..3f935cae 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -202,7 +202,8 @@ export default function extendConnector (Y/* :any */) { if (!conn.isSynced) { // it is crucial that isSynced is set at the time garbageCollectAfterSync is called conn.isSynced = true - yield * this.garbageCollectAfterSync() + // It is safer to remove this! + // TODO: remove: yield * this.garbageCollectAfterSync() // call whensynced listeners for (var f of conn.whenSyncedListeners) { f() @@ -343,7 +344,8 @@ export default function extendConnector (Y/* :any */) { } defer.resolve() }) - /* then apply ds + /* + then apply ds db.whenTransactionsFinished().then(() => { db.requestTransaction(function * () { yield * this.applyDeleteSet(m.deleteSet) diff --git a/src/Database.js b/src/Database.js index a6c15fbd..964b946e 100644 --- a/src/Database.js +++ b/src/Database.js @@ -39,6 +39,7 @@ export default function extendDatabase (Y /* :any */) { */ constructor (y, opts) { this.y = y + opts.gc = opts.gc === true this.dbOpts = opts var os = this this.userId = null @@ -121,7 +122,7 @@ export default function extendDatabase (Y /* :any */) { this.startRepairCheck() } startGarbageCollector () { - this.gc = this.dbOpts.gc == null || this.dbOpts.gc + this.gc = this.dbOpts.gc if (this.gc) { this.gcTimeout = !this.dbOpts.gcTimeout ? 50000 : this.dbOpts.gcTimeout } else { diff --git a/tests-lib/helper.js b/tests-lib/helper.js index 37f5da68..4d0ed0ad 100644 --- a/tests-lib/helper.js +++ b/tests-lib/helper.js @@ -17,7 +17,25 @@ export async function garbageCollectUsers (t, users) { await Promise.all(users.map(u => u.db.emptyGarbageCollector())) } +/* + * 1. reconnect and flush all + * 2. user 0 gc + * 3. get type content + * 4. disconnect & reconnect all (so gc is propagated) + * 5. compare os, ds, ss + */ export async function compareUsers (t, users) { + await Promise.all(users.map(u => u.reconnect())) + if (users[0].connector.testRoom == null) { + await wait(100) + } + await flushAll(t, users) + + await users[0].db.garbageCollect() + await users[0].db.garbageCollect() + + var userTypeContents = users.map(u => u.share.array._content.map(c => c.val || JSON.stringify(c.type))) + // disconnect all except user 0 await Promise.all(users.slice(1).map(async u => u.disconnect() @@ -27,9 +45,6 @@ export async function compareUsers (t, users) { } // reconnect all await Promise.all(users.map(u => u.reconnect())) - if (users[0].connector.testRoom != null) { - // flush for sync if test-connector - } if (users[0].connector.testRoom == null) { await wait(100) } @@ -40,13 +55,8 @@ export async function compareUsers (t, users) { }) )) - await flushAll(t, users) - // types must be equal before garbage collect - var userTypeContents = users.map(u => u.share.array._content.map(c => c.val || JSON.stringify(c.type))) var data = await Promise.all(users.map(async (u) => { var data = {} - await u.db.garbageCollect() - await u.db.garbageCollect() u.db.requestTransaction(function * () { var os = yield * this.getOperationsUntransformed() data.os = {} @@ -85,7 +95,7 @@ export async function initArrays (t, opts) { for (let i = 0; i < opts.users; i++) { let y = await Y({ connector: connector, - db: opts.db, + db: Object.assign({ gc: i === 0 }, opts.db), // Only one instance can gc! share: share }) result.users.push(y) @@ -108,7 +118,7 @@ export async function initArrays (t, opts) { } export async function flushAll (t, users) { - users = users.filter(u => u.connector.isSynced) + // users = users.filter(u => u.connector.isSynced) if (users.length === 0) { return }