fix several sync issues. improve performance a bit by removing ds from first sync step

This commit is contained in:
Kevin Jahns
2017-06-29 15:04:36 -07:00
parent 409a9414f1
commit a64730e651
3 changed files with 69 additions and 49 deletions

View File

@@ -93,9 +93,19 @@ export async function initArrays (t, opts) {
var chance = opts.chance || new Chance(t.getSeed() * 1000000000)
var connector = Object.assign({ room: 'debugging_' + t.name, testContext: t, chance }, opts.connector)
for (let i = 0; i < opts.users; i++) {
let dbOpts
let connOpts
if (i === 0) {
// Only one instance can gc!
dbOpts = Object.assign({ gc: true }, opts.db)
connOpts = Object.assign({ role: 'master' }, connector)
} else {
dbOpts = Object.assign({ gc: false }, opts.db)
connOpts = Object.assign({ role: 'slave' }, connector)
}
let y = await Y({
connector: connector,
db: Object.assign({ gc: i === 0 }, opts.db), // Only one instance can gc!
connector: connOpts,
db: dbOpts,
share: share
})
result.users.push(y)

View File

@@ -1,4 +1,5 @@
/* global Y */
import { wait } from './helper.js'
var rooms = {}
@@ -13,8 +14,8 @@ export class TestRoom {
connector.setUserId('' + (this.nextUserId++))
}
Object.keys(this.users).forEach(uid => {
this.users[uid].userJoined(connector.userId, 'master')
connector.userJoined(uid, 'master')
this.users[uid].userJoined(connector.userId, connector.role)
connector.userJoined(uid, this.users[uid].role)
})
this.users[connector.userId] = connector
}
@@ -43,6 +44,7 @@ export class TestRoom {
users = allUserIds.map(id => this.users[id].y)
}
while (flushing) {
await wait(10)
let res = await Promise.all(allUserIds.map(id => this.users[id]._flushAll(users)))
flushing = res.some(status => status === 'flushing')
}
@@ -65,7 +67,6 @@ export default function extendTestConnector (Y) {
if (options.room == null) {
throw new Error('You must define a room name!')
}
options.role = 'slave'
super(y, options)
this.options = options
this.room = options.room