finally fixed the timeout hack for tests

This commit is contained in:
Kevin Jahns
2015-11-18 16:17:59 +01:00
parent 5fcfbbfe94
commit 8ee563f873
4 changed files with 55 additions and 57 deletions

View File

@@ -7,6 +7,9 @@
// When testing, you store everything on the global object. We call it g
var Y = require('./y.js')
require('../../y-memory/src/Memory.js')(Y)
require('../../y-array/src/Array.js')(Y)
require('../../y-indexeddb/src/IndexedDB.js')(Y)
module.exports = Y
var g
@@ -33,6 +36,8 @@ g.describeManyTimes = function describeManyTimes (times, name, f) {
Wait for a specified amount of time (in ms). defaults to 5ms
*/
function wait (t) {
throw new Error("waiting..")
console.log("waiting..", t)
if (t == null) {
t = 5
}
@@ -45,13 +50,9 @@ function wait (t) {
g.wait = wait
g.databases = ['memory']
require('../../y-memory/src/Memory.js')(Y)
if (typeof window !== 'undefined') {
g.databases.push('indexeddb')
require('../../y-indexeddb/src/IndexedDB.js')(Y)
}
require('../../y-array/src/Array.js')
/*
returns a random element of o.
works on Object, and Array
@@ -86,10 +87,11 @@ function * applyTransactions (relAmount, numberOfTransactions, objects, users, t
var r = Math.random()
if (r >= 0.5) {
// 50% chance to flush
users[0].connector.flushOne() // flushes for some user.. (not necessarily 0)
Y.utils.globalRoom.flushOne() // flushes for some user.. (not necessarily 0)
} else if (r >= 0.05) {
// 45% chance to create operation
randomTransaction(getRandom(objects))
yield Y.utils.globalRoom.whenTransactionsFinished()
} else {
// 5% chance to disconnect/reconnect
var u = getRandom(users)
@@ -99,18 +101,15 @@ function * applyTransactions (relAmount, numberOfTransactions, objects, users, t
yield u.disconnect()
}
}
yield wait()
}
}
g.applyRandomTransactionsAllRejoinNoGC = async(function * applyRandomTransactions (users, objects, transactions, numberOfTransactions) {
yield* applyTransactions(1, numberOfTransactions, objects, users, transactions)
yield users[0].connector.flushAll()
yield wait()
for (var u in users) {
yield users[u].reconnect()
}
yield wait(100)
yield users[0].connector.flushAll()
yield g.garbageCollectAllUsers(users)
})
@@ -119,26 +118,21 @@ g.applyRandomTransactionsWithGC = async(function * applyRandomTransactions (user
yield* applyTransactions(1, numberOfTransactions, objects, users.slice(1), transactions)
yield users[0].connector.flushAll()
yield g.garbageCollectAllUsers(users)
yield wait(100)
for (var u in users) {
// TODO: here, we enforce that two users never sync at the same time with u[0]
// enforce that in the connector itself!
yield users[u].reconnect()
}
yield wait(100)
yield users[0].connector.flushAll()
yield wait(100)
yield g.garbageCollectAllUsers(users)
})
g.garbageCollectAllUsers = async(function * garbageCollectAllUsers (users) {
// gc two times because of the two gc phases (really collect everything)
yield wait(100)
for (var i in users) {
yield users[i].db.garbageCollect()
yield users[i].db.garbageCollect()
}
yield wait(100)
})
g.compareAllUsers = async(function * compareAllUsers (users) {
@@ -165,7 +159,6 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
})
}
yield users[0].connector.flushAll()
yield wait()
yield g.garbageCollectAllUsers(users)
for (var uid = 0; uid < users.length; uid++) {
@@ -196,7 +189,6 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
}
})
// compare allDels tree
yield wait()
if (s1 == null) {
u.db.requestTransaction(function * () {
yield* t1.call(this)
@@ -206,7 +198,6 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
db1.push(o)
})
})
yield wait()
} else {
// TODO: make requestTransaction return a promise..
u.db.requestTransaction(function * () {
@@ -221,8 +212,8 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
expect(db1[count++]).toEqual(o)
})
})
yield wait()
}
yield u.db.whenTransactionsFinished()
}
})