fixed some tests, lint, better run-scripts

This commit is contained in:
Kevin Jahns 2015-09-16 16:25:30 +02:00
parent 2a601ac6f6
commit 6f3a291ef5
8 changed files with 47 additions and 59 deletions

View File

@ -125,7 +125,7 @@ gulp.task('dev:browser', ['build:test'], function () {
gulp.watch('src/**/*.js', ['build:test']) gulp.watch('src/**/*.js', ['build:test'])
gulp.src(files.test) gulp.src(files.test)
.pipe(watch('build/**/*.js')) .pipe(watch(['build/**/*.js']))
.pipe(jasmineBrowser.specRunner()) .pipe(jasmineBrowser.specRunner())
.pipe(jasmineBrowser.server({port: options.testport})) .pipe(jasmineBrowser.server({port: options.testport}))
}) })

View File

@ -4,9 +4,9 @@
"description": "A framework for real-time p2p shared editing on arbitrary complex data types", "description": "A framework for real-time p2p shared editing on arbitrary complex data types",
"main": "y.js", "main": "y.js",
"scripts": { "scripts": {
"test": "gulp test", "test": "./node_modules/.bin/gulp test",
"lint": "standard", "lint": "./node_modules/.bin/standard",
"build": "gulp build" "build": "./node_modules/.bin/standard build"
}, },
"pre-commit": [ "pre-commit": [
"lint", "lint",

View File

@ -17,7 +17,7 @@ g.g = g
function wait (t) { function wait (t) {
if (t == null) { if (t == null) {
t = 10 t = 5
} }
var def = Promise.defer() var def = Promise.defer()
setTimeout(function () { setTimeout(function () {
@ -106,9 +106,9 @@ g.compareAllUsers = async(function * compareAllUsers (users) { //eslint-disable-
} }
yield users[0].connector.flushAll() yield users[0].connector.flushAll()
yield g.garbageCollectAllUsers(users) yield g.garbageCollectAllUsers(users)
yield wait(200) yield wait(50)
yield g.garbageCollectAllUsers(users) yield g.garbageCollectAllUsers(users)
yield wait(200) yield wait(50)
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
@ -202,4 +202,4 @@ function async (makeGenerator) {
} }
} }
} }
g.wrapCo = async g.async = async

View File

@ -2,7 +2,7 @@
'use strict' 'use strict'
class AbstractTransaction { // eslint-disable-line no-unused-vars class AbstractTransaction {
constructor (store) { constructor (store) {
this.store = store this.store = store
} }

View File

@ -207,8 +207,10 @@ class RBTree { // eslint-disable-line no-unused-vars
o_['id[1]'] = id[1] o_['id[1]'] = id[1]
os.push(o_) os.push(o_)
}) })
if (console.table != null) {
console.table(os) console.table(os)
} }
}
find (id) { find (id) {
return this.findNode(id).val return this.findNode(id).val
} }

View File

@ -27,14 +27,14 @@ var Struct = {
return op return op
}, },
requiredOps: function (op) { requiredOps: function (op) {
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
if (target.left === null || (yield* this.getOperation(target.left)).deleted) { if (target.left !== null && (yield* this.getOperation(target.left)).deleted) {
this.store.addToGarbageCollector(target.id) this.store.addToGarbageCollector(target.id)
target.gc = true target.gc = true
} }

View File

@ -1,35 +1,35 @@
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo, garbageCollectAllUsers */ /* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, async, garbageCollectAllUsers */
/* eslint-env browser,jasmine */ /* eslint-env browser,jasmine */
var numberOfYArrayTests = 5 var numberOfYArrayTests = 10
describe('Array Type', function () { describe('Array Type', function () {
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100 jasmine.DEFAULT_TIMEOUT_INTERVAL = 100
beforeEach(wrapCo(function * (done) { beforeEach(async(function * (done) {
yield createUsers(this, 3) yield 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
yield wait(100) yield wait(10)
done() done()
})) }))
afterEach(wrapCo(function * (done) { afterEach(async(function * (done) {
yield compareAllUsers(this.users) yield compareAllUsers(this.users)
done() done()
})) }))
describe('Basic tests', function () { describe('Basic tests', function () {
it('insert three elements, try re-get property', wrapCo(function * (done) { it('insert three elements, try re-get property', async(function * (done) {
var array = yield y1.set('Array', Y.Array) var array = yield y1.set('Array', Y.Array)
array.insert(0, [1, 2, 3]) array.insert(0, [1, 2, 3])
array = yield y1.get('Array') // re-get property array = yield y1.get('Array') // re-get property
expect(array.toArray()).toEqual([1, 2, 3]) expect(array.toArray()).toEqual([1, 2, 3])
done() done()
})) }))
it('Basic insert in array (handle three conflicts)', wrapCo(function * (done) { it('Basic insert in array (handle three conflicts)', async(function * (done) {
yield y1.set('Array', Y.Array) yield y1.set('Array', Y.Array)
yield flushAll() yield flushAll()
var l1 = yield y1.get('Array') var l1 = yield y1.get('Array')
@ -43,7 +43,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual(l3.toArray()) expect(l2.toArray()).toEqual(l3.toArray())
done() done()
})) }))
it('Basic insert&delete in array (handle three conflicts)', wrapCo(function * (done) { it('Basic insert&delete in array (handle three conflicts)', async(function * (done) {
var l1, l2, l3 var l1, l2, l3
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z']) l1.insert(0, ['x', 'y', 'z'])
@ -60,7 +60,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([0, 2, 'y']) expect(l2.toArray()).toEqual([0, 2, 'y'])
done() done()
})) }))
it('Handles getOperations ascending ids bug in late sync', wrapCo(function * (done) { it('Handles getOperations ascending ids bug in late sync', async(function * (done) {
var l1, l2 var l1, l2
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y']) l1.insert(0, ['x', 'y'])
@ -79,7 +79,7 @@ describe('Array Type', function () {
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
done() done()
})) }))
it('Handles deletions in late sync', wrapCo(function * (done) { it('Handles deletions in late sync', async(function * (done) {
var l1, l2 var l1, l2
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y']) l1.insert(0, ['x', 'y'])
@ -96,21 +96,18 @@ describe('Array Type', function () {
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
done() done()
})) }))
it('Handles deletions in late sync (2)', wrapCo(function * (done) { it('Handles deletions in late sync (2)', async(function * (done) {
var l1, l2 var l1, l2
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
yield flushAll() yield flushAll()
l2 = yield y2.get('Array') l2 = yield y2.get('Array')
l1.insert(0, ['x', 'y']) l1.insert(0, ['x', 'y'])
l1.delete(0, 2) l1.delete(0, 2)
yield wait()
yield flushAll() yield flushAll()
yield wait()
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
yield compareAllUsers(this.users)
done() done()
})) }))
it('Basic insert. Then delete the whole array', wrapCo(function * (done) { it('Basic insert. Then delete the whole array', async(function * (done) {
var l1, l2, l3 var l1, l2, l3
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z']) l1.insert(0, ['x', 'y', 'z'])
@ -124,7 +121,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([]) expect(l2.toArray()).toEqual([])
done() done()
})) }))
it('Basic insert. Then delete the whole array (merge listeners on late sync)', wrapCo(function * (done) { it('Basic insert. Then delete the whole array (merge listeners on late sync)', async(function * (done) {
var l1, l2, l3 var l1, l2, l3
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z']) l1.insert(0, ['x', 'y', 'z'])
@ -142,7 +139,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([]) expect(l2.toArray()).toEqual([])
done() done()
})) }))
it('Basic insert. Then delete the whole array (merge deleter on late sync)', wrapCo(function * (done) { it('Basic insert. Then delete the whole array (merge deleter on late sync)', async(function * (done) {
var l1, l2, l3 var l1, l2, l3
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z']) l1.insert(0, ['x', 'y', 'z'])
@ -150,9 +147,7 @@ describe('Array Type', function () {
yconfig1.disconnect() yconfig1.disconnect()
l1.delete(0, 3) l1.delete(0, 3)
l2 = yield y2.get('Array') l2 = yield y2.get('Array')
yield wait()
yconfig1.reconnect() yconfig1.reconnect()
yield wait()
l3 = yield y3.get('Array') l3 = yield y3.get('Array')
yield flushAll() yield flushAll()
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
@ -160,7 +155,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([]) expect(l2.toArray()).toEqual([])
done() done()
})) }))
it('throw insert & delete events', wrapCo(function * (done) { it('throw insert & delete events', async(function * (done) {
var array = yield this.users[0].root.set('array', Y.Array) var array = yield this.users[0].root.set('array', Y.Array)
var event var event
array.observe(function (e) { array.observe(function (e) {
@ -183,7 +178,7 @@ describe('Array Type', function () {
yield wait(50) yield wait(50)
done() done()
})) }))
it('garbage collects', wrapCo(function * (done) { it('garbage collects', async(function * (done) {
var l1, l2, l3 var l1, l2, l3
l1 = yield y1.set('Array', Y.Array) l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z']) l1.insert(0, ['x', 'y', 'z'])
@ -201,7 +196,6 @@ describe('Array Type', function () {
expect(l1.toArray()).toEqual(l2.toArray()) expect(l1.toArray()).toEqual(l2.toArray())
expect(l2.toArray()).toEqual(l3.toArray()) expect(l2.toArray()).toEqual(l3.toArray())
expect(l2.toArray()).toEqual([]) expect(l2.toArray()).toEqual([])
yield compareAllUsers(this.users)
done() done()
})) }))
}) })
@ -228,7 +222,7 @@ describe('Array Type', function () {
} }
} }
} }
beforeEach(wrapCo(function * (done) { beforeEach(async(function * (done) {
yield this.users[0].root.set('Array', Y.Array) yield this.users[0].root.set('Array', Y.Array)
yield flushAll() yield flushAll()
@ -239,11 +233,11 @@ describe('Array Type', function () {
this.arrays = yield Promise.all(promises) this.arrays = yield Promise.all(promises)
done() done()
})) }))
it('arrays.length equals users.length', wrapCo(function * (done) { // eslint-disable-line it('arrays.length equals users.length', async(function * (done) { // eslint-disable-line
expect(this.arrays.length).toEqual(this.users.length) expect(this.arrays.length).toEqual(this.users.length)
done() done()
})) }))
it(`succeed after ${numberOfYArrayTests} actions`, wrapCo(function * (done) { it(`succeed after ${numberOfYArrayTests} actions`, async(function * (done) {
for (var u of this.users) { for (var u of this.users) {
u.connector.debug = true u.connector.debug = true
} }

View File

@ -1,4 +1,4 @@
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo */ /* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, async */
/* eslint-env browser,jasmine */ /* eslint-env browser,jasmine */
var numberOfYMapTests = 5 var numberOfYMapTests = 5
@ -7,7 +7,7 @@ describe('Map Type', function () {
var y1, y2, y3, y4, flushAll var y1, y2, y3, y4, flushAll
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
beforeEach(wrapCo(function * (done) { beforeEach(async(function * (done) {
yield createUsers(this, 5) yield createUsers(this, 5)
y1 = this.users[0].root y1 = this.users[0].root
y2 = this.users[1].root y2 = this.users[1].root
@ -16,13 +16,13 @@ describe('Map Type', function () {
flushAll = this.users[0].connector.flushAll flushAll = this.users[0].connector.flushAll
done() done()
})) }))
afterEach(wrapCo(function * (done) { afterEach(async(function * (done) {
yield compareAllUsers(this.users) yield compareAllUsers(this.users)
done() done()
}), 5000) }), 5000)
describe('Basic tests', function () { describe('Basic tests', function () {
it('Basic get&set of Map property (converge via sync)', wrapCo(function * (done) { it('Basic get&set of Map property (converge via sync)', async(function * (done) {
y1.set('stuff', 'stuffy') y1.set('stuff', 'stuffy')
expect(y1.get('stuff')).toEqual('stuffy') expect(y1.get('stuff')).toEqual('stuffy')
yield flushAll() yield flushAll()
@ -30,26 +30,23 @@ describe('Map Type', function () {
var u = this.users[key].root var u = this.users[key].root
expect(u.get('stuff')).toEqual('stuffy') expect(u.get('stuff')).toEqual('stuffy')
} }
yield compareAllUsers(this.users)
done() done()
})) }))
it('Map can set custom types (Map)', wrapCo(function * (done) { it('Map can set custom types (Map)', async(function * (done) {
var map = yield y1.set('Map', Y.Map) var map = yield y1.set('Map', Y.Map)
map.set('one', 1) map.set('one', 1)
map = yield y1.get('Map') map = yield y1.get('Map')
expect(map.get('one')).toEqual(1) expect(map.get('one')).toEqual(1)
yield compareAllUsers(this.users)
done() done()
})) }))
it('Map can set custom types (Array)', wrapCo(function * (done) { it('Map can set custom types (Array)', async(function * (done) {
var array = yield y1.set('Array', Y.Array) var array = yield y1.set('Array', Y.Array)
array.insert(0, [1, 2, 3]) array.insert(0, [1, 2, 3])
array = yield y1.get('Array') array = yield y1.get('Array')
expect(array.toArray()).toEqual([1, 2, 3]) expect(array.toArray()).toEqual([1, 2, 3])
yield compareAllUsers(this.users)
done() done()
})) }))
it('Basic get&set of Map property (converge via update)', wrapCo(function * (done) { it('Basic get&set of Map property (converge via update)', async(function * (done) {
yield flushAll() yield flushAll()
y1.set('stuff', 'stuffy') y1.set('stuff', 'stuffy')
expect(y1.get('stuff')).toEqual('stuffy') expect(y1.get('stuff')).toEqual('stuffy')
@ -61,10 +58,9 @@ describe('Map Type', function () {
} }
done() done()
})) }))
it('Basic get&set of Map property (handle conflict)', wrapCo(function * (done) { it('Basic get&set of Map property (handle conflict)', async(function * (done) {
yield flushAll() yield flushAll()
y1.set('stuff', 'c0') y1.set('stuff', 'c0')
y2.set('stuff', 'c1') y2.set('stuff', 'c1')
yield flushAll() yield flushAll()
@ -72,10 +68,9 @@ describe('Map Type', function () {
var u = this.users[key] var u = this.users[key]
expect(u.root.get('stuff')).toEqual('c0') expect(u.root.get('stuff')).toEqual('c0')
} }
yield compareAllUsers(this.users)
done() done()
})) }))
it('Basic get&set&delete of Map property (handle conflict)', wrapCo(function * (done) { it('Basic get&set&delete of Map property (handle conflict)', async(function * (done) {
yield flushAll() yield flushAll()
y1.set('stuff', 'c0') y1.set('stuff', 'c0')
y1.delete('stuff') y1.delete('stuff')
@ -86,10 +81,9 @@ describe('Map Type', function () {
var u = this.users[key] var u = this.users[key]
expect(u.root.get('stuff')).toBeUndefined() expect(u.root.get('stuff')).toBeUndefined()
} }
yield compareAllUsers(this.users)
done() done()
})) }))
it('Basic get&set of Map property (handle three conflicts)', wrapCo(function * (done) { it('Basic get&set of Map property (handle three conflicts)', async(function * (done) {
yield flushAll() yield flushAll()
y1.set('stuff', 'c0') y1.set('stuff', 'c0')
y2.set('stuff', 'c1') y2.set('stuff', 'c1')
@ -101,10 +95,9 @@ describe('Map Type', function () {
var u = this.users[key] var u = this.users[key]
expect(u.root.get('stuff')).toEqual('c0') expect(u.root.get('stuff')).toEqual('c0')
} }
yield compareAllUsers(this.users)
done() done()
})) }))
it('Basic get&set&delete of Map property (handle three conflicts)', wrapCo(function * (done) { it('Basic get&set&delete of Map property (handle three conflicts)', async(function * (done) {
yield flushAll() yield flushAll()
y1.set('stuff', 'c0') y1.set('stuff', 'c0')
y2.set('stuff', 'c1') y2.set('stuff', 'c1')
@ -122,10 +115,9 @@ describe('Map Type', function () {
var u = this.users[key] var u = this.users[key]
expect(u.root.get('stuff')).toBeUndefined() expect(u.root.get('stuff')).toBeUndefined()
} }
yield compareAllUsers(this.users)
done() done()
})) }))
it('throws add & update & delete events (with type and primitive content)', wrapCo(function * (done) { it('throws add & update & delete events (with type and primitive content)', async(function * (done) {
var event var event
yield flushAll() yield flushAll()
y1.observe(function (e) { y1.observe(function (e) {
@ -186,7 +178,7 @@ describe('Map Type', function () {
} }
} }
} }
beforeEach(wrapCo(function * (done) { beforeEach(async(function * (done) {
yield y1.set('Map', Y.Map) yield y1.set('Map', Y.Map)
yield flushAll() yield flushAll()
@ -197,7 +189,7 @@ describe('Map Type', function () {
this.maps = yield Promise.all(promises) this.maps = yield Promise.all(promises)
done() done()
})) }))
it(`succeed after ${numberOfYMapTests} actions`, wrapCo(function * (done) { it(`succeed after ${numberOfYMapTests} actions`, async(function * (done) {
yield applyRandomTransactions(this.users, this.maps, randomMapTransactions, numberOfYMapTests) yield applyRandomTransactions(this.users, this.maps, randomMapTransactions, numberOfYMapTests)
yield flushAll() yield flushAll()
yield compareMapValues(this.maps) yield compareMapValues(this.maps)