fix first y-array test
This commit is contained in:
@@ -87,7 +87,7 @@ export async function compareUsers (t, users) {
|
||||
|
||||
var userArrayValues = users.map(u => u.get('array', Y.Array).toJSON())
|
||||
var userMapValues = users.map(u => u.get('map', Y.Map).toJSON())
|
||||
var userXmlValues = users.map(u => u.get('xml', Y.Xml).getDom().toString())
|
||||
var userXmlValues = users.map(u => u.get('xml', Y.Xml).toString())
|
||||
|
||||
// disconnect all except user 0
|
||||
await Promise.all(users.slice(1).map(async u =>
|
||||
@@ -107,28 +107,22 @@ export async function compareUsers (t, users) {
|
||||
u.connector.whenSynced(resolve)
|
||||
})
|
||||
))
|
||||
var data = users.forEach(u => {
|
||||
var data = users.map(u => {
|
||||
var data = {}
|
||||
let ops = []
|
||||
u.os.iterate(null, null, function (op) {
|
||||
if (!op._deleted) {
|
||||
ops.push({
|
||||
id: op._id,
|
||||
left: op._left,
|
||||
right: op._right,
|
||||
deleted: op._deleted
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
data.os = {}
|
||||
for (let i = 0; i < ops.length; i++) {
|
||||
let op = ops[i]
|
||||
op = Y.Struct[op.struct].encode(op)
|
||||
delete op.origin
|
||||
data.os[JSON.stringify(op.id)] = op
|
||||
}
|
||||
data.ds = getDeleteSet.apply(this)
|
||||
data.ss = getStateSet.apply(this)
|
||||
data.os = ops
|
||||
data.ds = getDeleteSet(u)
|
||||
data.ss = getStateSet(u)
|
||||
return data
|
||||
})
|
||||
for (var i = 0; i < data.length - 1; i++) {
|
||||
@@ -141,7 +135,7 @@ export async function compareUsers (t, users) {
|
||||
t.compare(data[i].ss, data[i + 1].ss, 'ss')
|
||||
}, `Compare user${i} with user${i + 1}`)
|
||||
}
|
||||
users.map(u => u.close())
|
||||
users.map(u => u.destroy())
|
||||
}
|
||||
|
||||
export async function initArrays (t, opts) {
|
||||
@@ -161,6 +155,7 @@ export async function initArrays (t, opts) {
|
||||
connector: connOpts
|
||||
})
|
||||
result.users.push(y)
|
||||
result['array' + i] = y.get('array', Y.Array)
|
||||
y.get('xml', Y.Xml).setDomFilter(function (d, attrs) {
|
||||
if (d.nodeName === 'HIDDEN') {
|
||||
return null
|
||||
@@ -193,9 +188,6 @@ export async function flushAll (t, users) {
|
||||
// use flushAll method specified in Test Connector
|
||||
await users[0].connector.testRoom.flushAll(users)
|
||||
} else {
|
||||
// flush for any connector
|
||||
await Promise.all(users.map(u => { return u.db.whenTransactionsFinished() }))
|
||||
|
||||
var flushCounter = users[0].get('flushHelper', Y.Map).get('0') || 0
|
||||
flushCounter++
|
||||
await Promise.all(users.map(async (u, i) => {
|
||||
|
||||
@@ -8,24 +8,21 @@ export class TestRoom {
|
||||
constructor (roomname) {
|
||||
this.room = roomname
|
||||
this.users = new Map()
|
||||
this.nextUserId = 0
|
||||
}
|
||||
join (connector) {
|
||||
if (connector.userId == null) {
|
||||
connector.setUserId(this.nextUserId++)
|
||||
}
|
||||
this.users.forEach((user, uid) => {
|
||||
if (user.role === 'master' || connector.role === 'master') {
|
||||
this.users.get(uid).userJoined(connector.userId, connector.role)
|
||||
const userID = connector.y.userID
|
||||
this.users.set(userID, connector)
|
||||
for (let [uid, user] of this.users) {
|
||||
if (uid !== userID && (user.role === 'master' || connector.role === 'master')) {
|
||||
connector.userJoined(uid, this.users.get(uid).role)
|
||||
this.users.get(uid).userJoined(userID, connector.role)
|
||||
}
|
||||
})
|
||||
this.users.set(connector.userId, connector)
|
||||
}
|
||||
}
|
||||
leave (connector) {
|
||||
this.users.delete(connector.userId)
|
||||
this.users.delete(connector.y.userID)
|
||||
this.users.forEach(user => {
|
||||
user.userLeft(connector.userId)
|
||||
user.userLeft(connector.y.userID)
|
||||
})
|
||||
}
|
||||
send (sender, receiver, m) {
|
||||
@@ -82,7 +79,7 @@ export default function extendTestConnector (Y) {
|
||||
return super.disconnect()
|
||||
}
|
||||
logBufferParsed () {
|
||||
console.log(' === Logging buffer of user ' + this.userId + ' === ')
|
||||
console.log(' === Logging buffer of user ' + this.y.userID + ' === ')
|
||||
for (let [user, conn] of this.connections) {
|
||||
console.log(` ${user}:`)
|
||||
for (let i = 0; i < conn.buffer.length; i++) {
|
||||
@@ -96,11 +93,11 @@ export default function extendTestConnector (Y) {
|
||||
}
|
||||
send (uid, message) {
|
||||
super.send(uid, message)
|
||||
this.testRoom.send(this.userId, uid, message)
|
||||
this.testRoom.send(this.y.userID, uid, message)
|
||||
}
|
||||
broadcast (message) {
|
||||
super.broadcast(message)
|
||||
this.testRoom.broadcast(this.userId, message)
|
||||
this.testRoom.broadcast(this.y.userID, message)
|
||||
}
|
||||
async whenSynced (f) {
|
||||
var synced = false
|
||||
@@ -119,7 +116,7 @@ export default function extendTestConnector (Y) {
|
||||
})
|
||||
}
|
||||
receiveMessage (sender, m) {
|
||||
if (this.userId !== sender && this.connections.has(sender)) {
|
||||
if (this.y.userID !== sender && this.connections.has(sender)) {
|
||||
var buffer = this.connections.get(sender).buffer
|
||||
if (buffer == null) {
|
||||
buffer = this.connections.get(sender).buffer = []
|
||||
@@ -135,30 +132,30 @@ export default function extendTestConnector (Y) {
|
||||
}
|
||||
}
|
||||
async _flushAll (flushUsers) {
|
||||
if (flushUsers.some(u => u.connector.userId === this.userId)) {
|
||||
if (flushUsers.some(u => u.connector.y.userID === this.y.userID)) {
|
||||
// this one needs to sync with every other user
|
||||
flushUsers = Array.from(this.connections.keys()).map(uid => this.testRoom.users.get(uid).y)
|
||||
}
|
||||
var finished = []
|
||||
for (let i = 0; i < flushUsers.length; i++) {
|
||||
let userId = flushUsers[i].connector.userId
|
||||
if (userId !== this.userId && this.connections.has(userId)) {
|
||||
let buffer = this.connections.get(userId).buffer
|
||||
let userID = flushUsers[i].connector.y.userID
|
||||
if (userID !== this.y.userID && this.connections.has(userID)) {
|
||||
let buffer = this.connections.get(userID).buffer
|
||||
if (buffer != null) {
|
||||
var messages = buffer.splice(0)
|
||||
for (let j = 0; j < messages.length; j++) {
|
||||
let p = super.receiveMessage(userId, messages[j])
|
||||
let p = super.receiveMessage(userID, messages[j])
|
||||
finished.push(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await Promise.all(finished)
|
||||
await this.y.db.whenTransactionsFinished()
|
||||
return finished.length > 0 ? 'flushing' : 'done'
|
||||
}
|
||||
}
|
||||
Y.extend('test', TestConnector)
|
||||
// TODO: this should be moved to a separate module (dont work on Y)
|
||||
Y.test = TestConnector
|
||||
}
|
||||
|
||||
if (typeof Y !== 'undefined') {
|
||||
|
||||
Reference in New Issue
Block a user