This commit is contained in:
Kevin Jahns 2015-09-09 20:29:39 +02:00
parent 06e7caab2d
commit b9e21665e2
6 changed files with 28 additions and 19 deletions

View File

@ -49,6 +49,7 @@ var jasmine = require('gulp-jasmine')
var jasmineBrowser = require('gulp-jasmine-browser') var jasmineBrowser = require('gulp-jasmine-browser')
var concat = require('gulp-concat') var concat = require('gulp-concat')
var watch = require('gulp-watch') var watch = require('gulp-watch')
var ignore = require('gulp-ignore')
var polyfills = [ var polyfills = [
'./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js' './node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
@ -95,7 +96,7 @@ gulp.task('build', function () {
blacklist: ['regenerator'], blacklist: ['regenerator'],
experimental: true experimental: true
})) }))
.pipe(sourcemaps.write()) .pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.')) .pipe(gulp.dest('.'))
}) })
@ -110,8 +111,9 @@ gulp.task('test', function () {
experimental: true experimental: true
})) }))
.pipe(uglify()) .pipe(uglify())
.pipe(sourcemaps.write()) .pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build')) .pipe(gulp.dest('build'))
.pipe(ignore.include('*.js'))
.pipe(jasmine({ .pipe(jasmine({
verbose: true, verbose: true,
includeStuckTrace: true includeStuckTrace: true
@ -125,9 +127,9 @@ gulp.task('build_jasmine_browser', function () {
.pipe(babel({ .pipe(babel({
loose: 'all', loose: 'all',
modules: 'ignore', modules: 'ignore',
optional: ['es7.asyncFunctions'], // optional: ['es7.asyncFunctions'],
// blacklist: "regenerator", blacklist: "regenerator",
experimental: true //experimental: true
})) }))
.pipe(sourcemaps.write()) .pipe(sourcemaps.write())
.pipe(gulp.dest('build')) .pipe(gulp.dest('build'))

View File

@ -5,7 +5,7 @@
This is just a compilation of functions that help to test this library! This is just a compilation of functions that help to test this library!
***/ ***/
function wait(t = 0) {//eslint-disable-line function wait(t = 10) {//eslint-disable-line
var def = Promise.defer() var def = Promise.defer()
setTimeout(function () { setTimeout(function () {
def.resolve() def.resolve()
@ -90,6 +90,8 @@ async function compareAllUsers(users){//eslint-disable-line
await users[0].connector.flushAll() await users[0].connector.flushAll()
await garbageCollectAllUsers(users) await garbageCollectAllUsers(users)
await wait(200) await wait(200)
await garbageCollectAllUsers(users)
await wait(200)
for (var uid = 0; uid < users.length; uid++) { for (var uid = 0; uid < users.length; uid++) {
var u = users[uid] var u = users[uid]
// compare deleted ops against deleteStore // compare deleted ops against deleteStore

View File

@ -209,12 +209,16 @@ class AbstractOperationStore { // eslint-disable-line no-unused-vars
state.clock++ state.clock++
yield* this.checkDeleteStoreForState(state) yield* this.checkDeleteStoreForState(state)
yield* this.setState(state) yield* this.setState(state)
var isDeleted = yield* this.store.ds.isDeleted(op.id)
yield* Struct[op.struct].execute.call(this, op) yield* Struct[op.struct].execute.call(this, op)
yield* this.addOperation(op) yield* this.addOperation(op)
yield* this.store.operationAdded(this, op) yield* this.store.operationAdded(this, op)
if (op.deleted === true) {
this.ds.delete(op.id) if (isDeleted) {
yield* Struct["Delete"].execute.call(this, {target: op.id})
} }
// find next operation to execute // find next operation to execute
op = this.store.waitingOperations.find([op.id[0], state.clock]) op = this.store.waitingOperations.find([op.id[0], state.clock])
if (op != null) { if (op != null) {

View File

@ -28,7 +28,7 @@ var Struct = {
return [] // [op.target] return [] // [op.target]
}, },
execute: function * (op) { execute: function * (op) {
console.log('Delete', op, console.trace()) // console.log('Delete', op, console.trace())
var target = yield* this.getOperation(op.target) var target = yield* this.getOperation(op.target)
if (target != null && !target.deleted) { if (target != null && !target.deleted) {
target.deleted = true target.deleted = true
@ -50,13 +50,11 @@ var Struct = {
yield* t._changed(this, copyObject(op)) yield* t._changed(this, copyObject(op))
} }
} }
if (target == null || !target.deleted) { this.ds.delete(op.target)
this.ds.delete(op.target) var state = yield* this.getState(op.target[0])
var state = yield* this.getState(op.target[0]) if (state.clock === op.target[1]) {
if (state === op.target[1]) { yield* this.checkDeleteStoreForState(state)
yield* this.checkDeleteStoreForState(state) yield* this.setState(state)
yield* this.setState(state)
}
} }
} }
}, },

View File

@ -8,10 +8,10 @@ describe('Array Type', function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000 jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
beforeEach(async function (done) { beforeEach(async function (done) {
await createUsers(this, 2) await createUsers(this, 3)
y1 = (yconfig1 = this.users[0]).root y1 = (yconfig1 = this.users[0]).root
y2 = (yconfig2 = this.users[1]).root y2 = (yconfig2 = this.users[1]).root
// y3 = (yconfig3 = this.users[2]).root y3 = (yconfig3 = this.users[2]).root
flushAll = this.users[0].connector.flushAll flushAll = this.users[0].connector.flushAll
done() done()
}) })
@ -102,8 +102,11 @@ describe('Array Type', function () {
l2 = await y2.get('Array') l2 = await y2.get('Array')
l1.insert(0, ['x', 'y']) l1.insert(0, ['x', 'y'])
l1.delete(0, 2) l1.delete(0, 2)
await wait(500)
await flushAll() await flushAll()
await wait(500)
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
await compareAllUsers(this.users)
done() done()
}) })
it('Basic insert. Then delete the whole array', async function (done) { it('Basic insert. Then delete the whole array', async function (done) {

View File

@ -15,7 +15,7 @@ class YConfig { // eslint-disable-line no-unused-vars
this.db = new Y[opts.db.name](this, opts.db) this.db = new Y[opts.db.name](this, opts.db)
this.connector = new Y[opts.connector.name](this, opts.connector) this.connector = new Y[opts.connector.name](this, opts.connector)
var yconfig = this var yconfig = this
this.db.requestTransaction(function *() { this.db.requestTransaction(function * requestTransaction () {
// create initial Map type // create initial Map type
var model = { var model = {
id: ['_', 0], id: ['_', 0],