enable gc in random tests

This commit is contained in:
Kevin Jahns 2017-06-19 21:16:42 +02:00
parent dfe3b0b1d1
commit 060549f2cb
4 changed files with 35 additions and 29 deletions

View File

@ -333,6 +333,7 @@ export default function extendConnector (Y/* :any */) {
}) })
this.syncStep2 = defer.promise this.syncStep2 = defer.promise
let m /* :MessageSyncStep2 */ = message let m /* :MessageSyncStep2 */ = message
// apply operations first
db.requestTransaction(function * () { db.requestTransaction(function * () {
yield * this.applyDeleteSet(m.deleteSet) yield * this.applyDeleteSet(m.deleteSet)
if (m.osUntransformed != null) { if (m.osUntransformed != null) {
@ -340,27 +341,15 @@ export default function extendConnector (Y/* :any */) {
} else { } else {
this.store.apply(m.os) this.store.apply(m.os)
} }
/*
* This just sends the complete hb after some time
* Mostly for debugging..
*
db.requestTransaction(function * () {
var ops = yield* this.getOperations(m.stateSet)
if (ops.length > 0) {
if (!broadcastHB) { // TODO: consider to broadcast here..
conn.send(sender, {
type: 'update',
ops: ops
})
} else {
// broadcast only once!
conn.broadcastOps(ops)
}
}
})
*/
defer.resolve() defer.resolve()
}) })
/* then apply ds
db.whenTransactionsFinished().then(() => {
db.requestTransaction(function * () {
yield * this.applyDeleteSet(m.deleteSet)
})
defer.resolve()
})*/
return this.syncStep2 return this.syncStep2
} else if (message.type === 'sync done') { } else if (message.type === 'sync done') {
var self = this var self = this

View File

@ -80,6 +80,10 @@ export default function extendDatabase (Y /* :any */) {
function garbageCollect () { function garbageCollect () {
return os.whenTransactionsFinished().then(function () { return os.whenTransactionsFinished().then(function () {
if (os.gcTimeout > 0 && (os.gc1.length > 0 || os.gc2.length > 0)) { if (os.gcTimeout > 0 && (os.gc1.length > 0 || os.gc2.length > 0)) {
// debug
if (os.y.connector.isSynced === false) {
debugger
}
if (!os.y.connector.isSynced) { if (!os.y.connector.isSynced) {
console.warn('gc should be empty when not synced!') console.warn('gc should be empty when not synced!')
} }

View File

@ -996,6 +996,7 @@ export default function extendTransaction (Y) {
op = Y.Struct[op.struct].encode(o) op = Y.Struct[op.struct].encode(o)
op.right = newright op.right = newright
if (missingOrigins.length > 0) { if (missingOrigins.length > 0) {
debugger
console.log('This should not happen .. :( please report this') console.log('This should not happen .. :( please report this')
} }
missingOrigins = [op] missingOrigins = [op]

View File

@ -12,23 +12,34 @@ export let Y = _Y
Y.extend(yMemory, yArray, yMap, yTest) Y.extend(yMemory, yArray, yMap, yTest)
export async function garbageCollectAllUsers (t, users) { export async function garbageCollectUsers (t, users) {
await flushAll(t, users) await flushAll(t, users)
await Promise.all(users.map(u => u.db.emptyGarbageCollector())) await Promise.all(users.map(u => u.db.emptyGarbageCollector()))
} }
export async function compareUsers (t, users) { export async function compareUsers (t, users) {
var unsynced = users.filter(u => !u.connector.isSynced) // disconnect all except user 0
unsynced.forEach(u => u.reconnect()) await Promise.all(users.slice(1).map(async u =>
u.disconnect()
))
if (users[0].connector.testRoom == null) {
await wait(100)
}
// reconnect all
await Promise.all(users.map(u => u.reconnect()))
if (users[0].connector.testRoom != null) { if (users[0].connector.testRoom != null) {
// flush for sync if test-connector // flush for sync if test-connector
await users[0].connector.testRoom.flushAll(users)
} }
await Promise.all(unsynced.map(u => { if (users[0].connector.testRoom == null) {
return new Promise(function (resolve) { await wait(100)
}
await users[0].connector.testRoom.flushAll(users)
await Promise.all(users.map(u =>
new Promise(function (resolve) {
u.connector.whenSynced(resolve) u.connector.whenSynced(resolve)
}) })
})) ))
await flushAll(t, users) await flushAll(t, users)
// types must be equal before garbage collect // 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 userTypeContents = users.map(u => u.share.array._content.map(c => c.val || JSON.stringify(c.type)))
@ -37,9 +48,10 @@ export async function compareUsers (t, users) {
await u.db.garbageCollect() await u.db.garbageCollect()
await u.db.garbageCollect() await u.db.garbageCollect()
u.db.requestTransaction(function * () { u.db.requestTransaction(function * () {
data.os = yield * this.getOperationsUntransformed() var os = yield * this.getOperationsUntransformed()
data.os = data.os.untransformed.map((op) => { data.os = os.untransformed.map((op) => {
return Y.Struct[op.struct].encode(op) op = Y.Struct[op.struct].encode(op)
delete op.origin
}) })
data.ds = yield * this.getDeleteSet() data.ds = yield * this.getDeleteSet()
data.ss = yield * this.getStateSet() data.ss = yield * this.getStateSet()