diff --git a/dist b/dist index 3eafd787..e30e16c9 160000 --- a/dist +++ b/dist @@ -1 +1 @@ -Subproject commit 3eafd78710a30cd01bf4c6b3553c141e7ac604a5 +Subproject commit e30e16c91bfab65b1e9347d21dbda8d23e12ef03 diff --git a/src/Connector.js b/src/Connector.js index bc2fc722..6a4e5005 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -76,6 +76,7 @@ module.exports = function (Y/* :any */) { } reconnect () { this.log('reconnecting..') + this.y.db.startGarbageCollector() } disconnect () { this.log('discronnecting..') diff --git a/src/Connectors/Test.js b/src/Connectors/Test.js index ce7d520d..05b16519 100644 --- a/src/Connectors/Test.js +++ b/src/Connectors/Test.js @@ -147,11 +147,15 @@ module.exports = function (Y) { return Y.utils.globalRoom.flushAll() } disconnect () { + var waitForMe = Promise.resolve() if (!this.isDisconnected()) { globalRoom.removeUser(this.userId) - super.disconnect() + waitForMe = super.disconnect() } - return this.y.db.whenTransactionsFinished() + var self = this + return waitForMe.then(function () { + return self.y.db.whenTransactionsFinished() + }) } flush () { var self = this diff --git a/src/Database.js b/src/Database.js index 811bf5ad..d693aacd 100644 --- a/src/Database.js +++ b/src/Database.js @@ -39,6 +39,7 @@ module.exports = function (Y /* :any */) { */ constructor (y, opts) { this.y = y + this.dbOpts = opts var os = this this.userId = null var resolve @@ -75,12 +76,6 @@ module.exports = function (Y /* :any */) { } this.gc1 = [] // first stage this.gc2 = [] // second stage -> after that, remove the op - this.gc = opts.gc == null || opts.gc - if (this.gc) { - this.gcTimeout = !opts.gcTimeout ? 50000 : opts.gcTimeout - } else { - this.gcTimeout = -1 - } function garbageCollect () { return os.whenTransactionsFinished().then(function () { @@ -115,13 +110,23 @@ module.exports = function (Y /* :any */) { }) } this.garbageCollect = garbageCollect - if (this.gcTimeout > 0) { - garbageCollect() - } + this.startGarbageCollector() + this.repairCheckInterval = !opts.repairCheckInterval ? 6000 : opts.repairCheckInterval this.opsReceivedTimestamp = new Date() this.startRepairCheck() } + startGarbageCollector () { + this.gc = this.dbOpts.gc == null || this.dbOpts.gc + if (this.gc) { + this.gcTimeout = !this.dbOpts.gcTimeout ? 50000 : this.dbOpts.gcTimeout + } else { + this.gcTimeout = -1 + } + if (this.gcTimeout > 0) { + this.garbageCollect() + } + } startRepairCheck () { var os = this if (this.repairCheckInterval > 0) { diff --git a/src/SpecHelper.js b/src/SpecHelper.js index 24eded79..f6861686 100644 --- a/src/SpecHelper.js +++ b/src/SpecHelper.js @@ -228,6 +228,20 @@ g.compareAllUsers = async(function * compareAllUsers (users) { var allDels1, allDels2 // all deletions var db1 = [] // operation store of user1 + yield Y.utils.globalRoom.flushAll() + yield g.garbageCollectAllUsers(users) + yield Y.utils.globalRoom.flushAll() + + // disconnect, then reconnect all users + // We do this to make sure that the gc is updated by everyone + for (var i = 0; i < users.length; i++) { + yield users[i].disconnect() + yield wait() + yield users[i].reconnect() + } + yield wait() + yield Y.utils.globalRoom.flushAll() + // t1 and t2 basically do the same. They define t[1,2], ds[1,2], and allDels[1,2] function * t1 () { s1 = yield* this.getStateSet() @@ -245,9 +259,7 @@ g.compareAllUsers = async(function * compareAllUsers (users) { allDels2.push(d) }) } - yield Y.utils.globalRoom.flushAll() - yield g.garbageCollectAllUsers(users) - yield Y.utils.globalRoom.flushAll() + var buffer = Y.utils.globalRoom.buffers for (var name in buffer) { if (buffer[name].length > 0) { @@ -338,6 +350,7 @@ g.createUsers = async(function * createUsers (self, numberOfUsers, database, ini namespace: 'User ' + i, cleanStart: true, gcTimeout: -1, + gc: true, repairCheckInterval: -1 }, connector: {