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
let m /* :MessageSyncStep2 */ = message
// apply operations first
db.requestTransaction(function * () {
yield * this.applyDeleteSet(m.deleteSet)
if (m.osUntransformed != null) {
@ -340,27 +341,15 @@ export default function extendConnector (Y/* :any */) {
} else {
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()
})
/* then apply ds
db.whenTransactionsFinished().then(() => {
db.requestTransaction(function * () {
yield * this.applyDeleteSet(m.deleteSet)
})
defer.resolve()
})*/
return this.syncStep2
} else if (message.type === 'sync done') {
var self = this

View File

@ -80,6 +80,10 @@ export default function extendDatabase (Y /* :any */) {
function garbageCollect () {
return os.whenTransactionsFinished().then(function () {
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) {
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.right = newright
if (missingOrigins.length > 0) {
debugger
console.log('This should not happen .. :( please report this')
}
missingOrigins = [op]

View File

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