fixed all insert tests
This commit is contained in:
parent
9d1ad8cb28
commit
e8170a09a7
@ -231,9 +231,12 @@ export default class Item {
|
|||||||
if (info & 0b1) {
|
if (info & 0b1) {
|
||||||
encoder.writeID(this._origin._lastId)
|
encoder.writeID(this._origin._lastId)
|
||||||
}
|
}
|
||||||
|
// TODO: remove
|
||||||
|
/* see above
|
||||||
if (info & 0b10) {
|
if (info & 0b10) {
|
||||||
encoder.writeID(this._left._lastId)
|
encoder.writeID(this._left._lastId)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (info & 0b100) {
|
if (info & 0b100) {
|
||||||
encoder.writeID(this._right_origin._id)
|
encoder.writeID(this._right_origin._id)
|
||||||
}
|
}
|
||||||
@ -254,34 +257,33 @@ export default class Item {
|
|||||||
if (info & 0b1) {
|
if (info & 0b1) {
|
||||||
// origin != null
|
// origin != null
|
||||||
const originID = decoder.readID()
|
const originID = decoder.readID()
|
||||||
if (this._origin === null) {
|
// we have to query for left again because it might have been split/merged..
|
||||||
const origin = y.os.getItemCleanEnd(originID)
|
const origin = y.os.getItemCleanEnd(originID)
|
||||||
if (origin === null) {
|
if (origin === null) {
|
||||||
missing.push(originID)
|
missing.push(originID)
|
||||||
} else {
|
} else {
|
||||||
this._origin = origin
|
this._origin = origin
|
||||||
this._left = this._origin
|
this._left = this._origin
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// read right
|
// read right
|
||||||
if (info & 0b100) {
|
if (info & 0b100) {
|
||||||
// right != null
|
// right != null
|
||||||
const rightID = decoder.readID()
|
const rightID = decoder.readID()
|
||||||
if (this._right_origin === null) {
|
// we have to query for right again because it might have been split/merged..
|
||||||
const right = y.os.getItemCleanStart(rightID)
|
const right = y.os.getItemCleanStart(rightID)
|
||||||
if (right === null) {
|
if (right === null) {
|
||||||
missing.push(rightID)
|
missing.push(rightID)
|
||||||
} else {
|
} else {
|
||||||
this._right = right
|
this._right = right
|
||||||
this._right_origin = right
|
this._right_origin = right
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// read parent
|
// read parent
|
||||||
if (~info & 0b101) {
|
if (~info & 0b101) {
|
||||||
// neither origin nor right is defined
|
// neither origin nor right is defined
|
||||||
const parentID = decoder.readID()
|
const parentID = decoder.readID()
|
||||||
|
// parent does not change, so we don't have to search for it again
|
||||||
if (this._parent === null) {
|
if (this._parent === null) {
|
||||||
const parent = y.os.get(parentID)
|
const parent = y.os.get(parentID)
|
||||||
if (parent === null) {
|
if (parent === null) {
|
||||||
|
@ -2,7 +2,6 @@ import { wait, initArrays, compareUsers, Y, flushAll, applyRandomTests } from '.
|
|||||||
import { test, proxyConsole } from 'cutest'
|
import { test, proxyConsole } from 'cutest'
|
||||||
|
|
||||||
proxyConsole()
|
proxyConsole()
|
||||||
|
|
||||||
test('basic spec', async function array0 (t) {
|
test('basic spec', async function array0 (t) {
|
||||||
let { users, array0 } = await initArrays(t, { users: 2 })
|
let { users, array0 } = await initArrays(t, { users: 2 })
|
||||||
|
|
||||||
@ -229,7 +228,6 @@ var arrayTransactions = [
|
|||||||
var pos = chance.integer({ min: 0, max: yarray.length })
|
var pos = chance.integer({ min: 0, max: yarray.length })
|
||||||
yarray.insert(pos, content)
|
yarray.insert(pos, content)
|
||||||
},
|
},
|
||||||
/*
|
|
||||||
function insertTypeArray (t, user, chance) {
|
function insertTypeArray (t, user, chance) {
|
||||||
const yarray = user.get('array', Y.Array)
|
const yarray = user.get('array', Y.Array)
|
||||||
var pos = chance.integer({ min: 0, max: yarray.length })
|
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) {
|
test('y-array: Random tests (20)', async function randomArray20 (t) {
|
||||||
await applyRandomTests(t, arrayTransactions, 30)
|
await applyRandomTests(t, arrayTransactions, 20)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('y-array: Random tests (42)', async function randomArray42 (t) {
|
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)
|
await applyRandomTests(t, arrayTransactions, 47)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
test('y-array: Random tests (200)', async function randomArray200 (t) {
|
test('y-array: Random tests (200)', async function randomArray200 (t) {
|
||||||
await applyRandomTests(t, arrayTransactions, 200)
|
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) {
|
test('y-array: Random tests (500)', async function randomArray500 (t) {
|
||||||
await applyRandomTests(t, arrayTransactions, 500)
|
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)
|
||||||
|
})
|
||||||
|
@ -248,8 +248,6 @@ export function wait (t) {
|
|||||||
|
|
||||||
export async function applyRandomTests (t, mods, iterations) {
|
export async function applyRandomTests (t, mods, iterations) {
|
||||||
const chance = new Chance(t.getSeed() * 1000000000)
|
const chance = new Chance(t.getSeed() * 1000000000)
|
||||||
// TODO: remove
|
|
||||||
console.info('seed: ' + t._seed)
|
|
||||||
var initInformation = await initArrays(t, { users: 5, chance: chance })
|
var initInformation = await initArrays(t, { users: 5, chance: chance })
|
||||||
let { users } = initInformation
|
let { users } = initInformation
|
||||||
for (var i = 0; i < iterations; i++) {
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
@ -14,8 +14,15 @@ export class TestRoom {
|
|||||||
this.users.set(userID, connector)
|
this.users.set(userID, connector)
|
||||||
for (let [uid, user] of this.users) {
|
for (let [uid, user] of this.users) {
|
||||||
if (uid !== userID && (user.role === 'master' || connector.role === 'master')) {
|
if (uid !== userID && (user.role === 'master' || connector.role === 'master')) {
|
||||||
connector.userJoined(uid, user.role)
|
// The order is important because there is no timeout in send/receiveMessage
|
||||||
user.userJoined(userID, connector.role)
|
// (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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user