fix some tests, implement event classes for types, and re-implement logging
This commit is contained in:
@@ -5,6 +5,7 @@ import yTest from './test-connector.js'
|
||||
import Chance from 'chance'
|
||||
import ItemJSON from '../src/Struct/ItemJSON.js'
|
||||
import ItemString from '../src/Struct/ItemString.js'
|
||||
import { defragmentItemContent } from '../src/Util/defragmentItemContent.js'
|
||||
|
||||
export const Y = _Y
|
||||
|
||||
@@ -86,8 +87,12 @@ export async function compareUsers (t, users) {
|
||||
await flushAll(t, users)
|
||||
await wait()
|
||||
await flushAll(t, users)
|
||||
await wait()
|
||||
await flushAll(t, users)
|
||||
await wait()
|
||||
await flushAll(t, users)
|
||||
|
||||
var userArrayValues = users.map(u => u.get('array', Y.Array).toJSON())
|
||||
var userArrayValues = users.map(u => u.get('array', Y.Array).toJSON().map(val => JSON.stringify(val)))
|
||||
var userMapValues = users.map(u => u.get('map', Y.Map).toJSON())
|
||||
var userXmlValues = users.map(u => u.get('xml', Y.Xml).toString())
|
||||
|
||||
@@ -110,22 +115,21 @@ export async function compareUsers (t, users) {
|
||||
})
|
||||
))
|
||||
var data = users.map(u => {
|
||||
defragmentItemContent(u)
|
||||
var data = {}
|
||||
let ops = []
|
||||
u.os.iterate(null, null, function (op) {
|
||||
if (!op._deleted) {
|
||||
const json = {
|
||||
id: op._id,
|
||||
left: op._left === null ? null : op._left._id,
|
||||
right: op._right === null ? null : op._right._id,
|
||||
length: op._length,
|
||||
deleted: op._deleted
|
||||
}
|
||||
if (op instanceof ItemJSON || op instanceof ItemString) {
|
||||
json.content = op._content
|
||||
}
|
||||
ops.push(json)
|
||||
const json = {
|
||||
id: op._id,
|
||||
left: op._left === null ? null : op._left._id,
|
||||
right: op._right === null ? null : op._right._id,
|
||||
length: op._length,
|
||||
deleted: op._deleted
|
||||
}
|
||||
if (op instanceof ItemJSON || op instanceof ItemString) {
|
||||
json.content = op._content
|
||||
}
|
||||
ops.push(json)
|
||||
})
|
||||
data.os = ops
|
||||
data.ds = getDeleteSet(u)
|
||||
@@ -173,6 +177,13 @@ export async function initArrays (t, opts) {
|
||||
return attrs.filter(a => a !== 'hidden')
|
||||
}
|
||||
})
|
||||
y.on('afterTransaction', function () {
|
||||
for (let missing of y._missingStructs.values()) {
|
||||
if (Array.from(missing.values()).length > 0) {
|
||||
console.error(new Error('Test check in "afterTransaction": missing should be empty!'))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
result.array0.delete(0, result.array0.length)
|
||||
if (result.users[0].connector.testRoom != null) {
|
||||
@@ -266,7 +277,7 @@ export async function applyRandomTests (t, mods, iterations) {
|
||||
// TODO: We do not gc all users as this does not work yet
|
||||
// await garbageCollectUsers(t, users)
|
||||
await flushAll(t, users)
|
||||
await users[0].db.emptyGarbageCollector()
|
||||
// await users[0].db.emptyGarbageCollector()
|
||||
await flushAll(t, users)
|
||||
} else if (chance.bool({likelihood: 10})) {
|
||||
// 20%*!prev chance to flush some operations
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* global Y */
|
||||
import { wait } from './helper'
|
||||
import { messageToString, messageToRoomname } from '../src/MessageHandler/messageToString'
|
||||
import { messageToString } from '../src/MessageHandler/messageToString'
|
||||
|
||||
var rooms = {}
|
||||
|
||||
@@ -14,8 +14,8 @@ export class TestRoom {
|
||||
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)
|
||||
connector.userJoined(uid, user.role)
|
||||
user.userJoined(userID, connector.role)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,13 @@ export class TestRoom {
|
||||
}
|
||||
async flushAll (users) {
|
||||
let flushing = true
|
||||
let allUserIds = Array.from(this.users.keys())
|
||||
let allUsers = Array.from(this.users.values())
|
||||
if (users == null) {
|
||||
users = allUserIds.map(id => this.users.get(id).y)
|
||||
users = allUsers.map(user => user.y)
|
||||
}
|
||||
while (flushing) {
|
||||
await wait(10)
|
||||
let res = await Promise.all(allUserIds.map(id => this.users.get(id)._flushAll(users)))
|
||||
let res = await Promise.all(allUsers.map(user => user._flushAll(users)))
|
||||
flushing = res.some(status => status === 'flushing')
|
||||
}
|
||||
}
|
||||
@@ -83,13 +83,16 @@ export default function extendTestConnector (Y) {
|
||||
for (let [user, conn] of this.connections) {
|
||||
console.log(` ${user}:`)
|
||||
for (let i = 0; i < conn.buffer.length; i++) {
|
||||
console.log(formatYjsMessage(conn.buffer[i]))
|
||||
console.log(messageToString(conn.buffer[i]))
|
||||
}
|
||||
}
|
||||
}
|
||||
reconnect () {
|
||||
this.testRoom.join(this)
|
||||
return super.reconnect()
|
||||
super.reconnect()
|
||||
return new Promise(resolve => {
|
||||
this.whenSynced(resolve)
|
||||
})
|
||||
}
|
||||
send (uid, message) {
|
||||
super.send(uid, message)
|
||||
@@ -116,20 +119,22 @@ export default function extendTestConnector (Y) {
|
||||
})
|
||||
}
|
||||
receiveMessage (sender, m) {
|
||||
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 = []
|
||||
setTimeout(() => {
|
||||
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 = []
|
||||
}
|
||||
buffer.push(m)
|
||||
if (this.chance.bool({likelihood: 30})) {
|
||||
// flush 1/2 with 30% chance
|
||||
var flushLength = Math.round(buffer.length / 2)
|
||||
buffer.splice(0, flushLength).forEach(m => {
|
||||
super.receiveMessage(sender, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
buffer.push(m)
|
||||
if (this.chance.bool({likelihood: 30})) {
|
||||
// flush 1/2 with 30% chance
|
||||
var flushLength = Math.round(buffer.length / 2)
|
||||
buffer.splice(0, flushLength).forEach(m => {
|
||||
super.receiveMessage(sender, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
async _flushAll (flushUsers) {
|
||||
if (flushUsers.some(u => u.connector.y.userID === this.y.userID)) {
|
||||
|
||||
Reference in New Issue
Block a user