fixed some issues in random tests

This commit is contained in:
Kevin Jahns
2019-03-06 13:29:16 +01:00
parent 99e3e95a00
commit 76b7d0b651
6 changed files with 1987 additions and 256 deletions

View File

@@ -5,6 +5,7 @@
import { getStruct } from 'y-protocols/sync.js'
import * as decoding from 'funlib/decoding.js'
import { GC } from '../structs/GC.js'
import { Delete } from '../structs/Delete.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Item } from '../structs/Item.js' // eslint-disable-line
@@ -56,6 +57,9 @@ function _integrateRemoteStructHelper (y, struct) {
decoder.pos = oldPos
if (missing.length === 0) {
y._readyToIntegrate.push(missingDef.struct)
// TODO: sorting should be optimized
// Sorting because deletes may change the origin of ops
y._readyToIntegrate.sort((a, b) => a.constructor === b.constructor ? 0 : (a.constructor === Delete ? 1 : -1))
} else {
// TODO: throw error here
}
@@ -84,6 +88,7 @@ export const integrateRemoteStructs = (decoder, y) => {
let decoderPos = decoder.pos
let missing = struct._fromBinary(y, decoder)
if (missing.length === 0) {
y._readyToIntegrate.sort((a, b) => a.constructor === b.constructor ? 0 : (a.constructor === Delete ? 1 : -1))
while (struct != null) {
_integrateRemoteStructHelper(y, struct)
struct = y._readyToIntegrate.shift()
@@ -121,6 +126,7 @@ export const integrateRemoteStruct = (decoder, y) => {
let decoderPos = decoder.pos
let missing = struct._fromBinary(y, decoder)
if (missing.length === 0) {
y._readyToIntegrate.sort((a, b) => a.constructor === b.constructor ? 0 : (a.constructor === Delete ? 1 : -1))
while (struct != null) {
_integrateRemoteStructHelper(y, struct)
struct = y._readyToIntegrate.shift()