fixed all insert tests

This commit is contained in:
Kevin Jahns 2017-10-26 14:40:21 +02:00
parent 9d1ad8cb28
commit e8170a09a7
4 changed files with 37 additions and 27 deletions

View File

@ -231,9 +231,12 @@ export default class Item {
if (info & 0b1) {
encoder.writeID(this._origin._lastId)
}
// TODO: remove
/* see above
if (info & 0b10) {
encoder.writeID(this._left._lastId)
}
*/
if (info & 0b100) {
encoder.writeID(this._right_origin._id)
}
@ -254,34 +257,33 @@ export default class Item {
if (info & 0b1) {
// origin != null
const originID = decoder.readID()
if (this._origin === null) {
const origin = y.os.getItemCleanEnd(originID)
if (origin === null) {
missing.push(originID)
} else {
this._origin = origin
this._left = this._origin
}
// we have to query for left again because it might have been split/merged..
const origin = y.os.getItemCleanEnd(originID)
if (origin === null) {
missing.push(originID)
} else {
this._origin = origin
this._left = this._origin
}
}
// read right
if (info & 0b100) {
// right != null
const rightID = decoder.readID()
if (this._right_origin === null) {
const right = y.os.getItemCleanStart(rightID)
if (right === null) {
missing.push(rightID)
} else {
this._right = right
this._right_origin = right
}
// we have to query for right again because it might have been split/merged..
const right = y.os.getItemCleanStart(rightID)
if (right === null) {
missing.push(rightID)
} else {
this._right = right
this._right_origin = right
}
}
// read parent
if (~info & 0b101) {
// neither origin nor right is defined
const parentID = decoder.readID()
// parent does not change, so we don't have to search for it again
if (this._parent === null) {
const parent = y.os.get(parentID)
if (parent === null) {

View File

@ -2,7 +2,6 @@ import { wait, initArrays, compareUsers, Y, flushAll, applyRandomTests } from '.
import { test, proxyConsole } from 'cutest'
proxyConsole()
test('basic spec', async function array0 (t) {
let { users, array0 } = await initArrays(t, { users: 2 })
@ -229,7 +228,6 @@ var arrayTransactions = [
var pos = chance.integer({ min: 0, max: yarray.length })
yarray.insert(pos, content)
},
/*
function insertTypeArray (t, user, chance) {
const yarray = user.get('array', Y.Array)
var pos = chance.integer({ min: 0, max: yarray.length })
@ -268,11 +266,10 @@ var arrayTransactions = [
}
}
}
*/
]
test('y-array: Random tests (5)', async function randomArray5 (t) {
await applyRandomTests(t, arrayTransactions, 30)
test('y-array: Random tests (20)', async function randomArray20 (t) {
await applyRandomTests(t, arrayTransactions, 20)
})
test('y-array: Random tests (42)', async function randomArray42 (t) {
@ -299,7 +296,6 @@ test('y-array: Random tests (47)', async function randomArray47 (t) {
await applyRandomTests(t, arrayTransactions, 47)
})
/*
test('y-array: Random tests (200)', async function randomArray200 (t) {
await applyRandomTests(t, arrayTransactions, 200)
})
@ -315,4 +311,11 @@ test('y-array: Random tests (400)', async function randomArray400 (t) {
test('y-array: Random tests (500)', async function randomArray500 (t) {
await applyRandomTests(t, arrayTransactions, 500)
})
*/
test('y-array: Random tests (1000)', async function randomArray1000 (t) {
await applyRandomTests(t, arrayTransactions, 1000)
})
test('y-array: Random tests (2000)', async function randomArray2000 (t) {
await applyRandomTests(t, arrayTransactions, 2000)
})

View File

@ -248,8 +248,6 @@ export function wait (t) {
export async function applyRandomTests (t, mods, iterations) {
const chance = new Chance(t.getSeed() * 1000000000)
// TODO: remove
console.info('seed: ' + t._seed)
var initInformation = await initArrays(t, { users: 5, chance: chance })
let { users } = initInformation
for (var i = 0; i < iterations; i++) {

View File

@ -14,8 +14,15 @@ 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, user.role)
user.userJoined(userID, connector.role)
// The order is important because there is no timeout in send/receiveMessage
// (the user that receives a sync step must already now about the sender)
if (user.role === 'master') {
connector.userJoined(uid, user.role)
user.userJoined(userID, connector.role)
} else if (connector.role === 'master') {
user.userJoined(userID, connector.role)
connector.userJoined(uid, user.role)
}
}
}
}