mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Add tests for replication status information
Use latest store modules Add a set of tests for checking database replication status Fix tests as per new replication status api
This commit is contained in:
@@ -132,14 +132,18 @@ Object.keys(testAPIs).forEach(API => {
|
||||
db = await orbitdb1.eventlog(address)
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let count = 0
|
||||
db.events.on('load.progress', (address, hash, entry, progress, total) => {
|
||||
db.events.on('load.progress', (address, hash, entry) => {
|
||||
count ++
|
||||
try {
|
||||
assert.equal(address, db.address.toString())
|
||||
assert.equal(total, entryCount)
|
||||
|
||||
const { progress, max } = db.replicationStatus
|
||||
assert.equal(max, entryCount)
|
||||
assert.equal(progress, count)
|
||||
|
||||
assert.notEqual(hash, null)
|
||||
assert.notEqual(entry, null)
|
||||
|
||||
if (progress === entryCount && count === entryCount) {
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
@@ -246,12 +250,15 @@ Object.keys(testAPIs).forEach(API => {
|
||||
db = await orbitdb1.eventlog(address)
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let count = 0
|
||||
db.events.on('load.progress', (address, hash, entry, progress, total) => {
|
||||
db.events.on('load.progress', (address, hash, entry) => {
|
||||
count ++
|
||||
try {
|
||||
assert.equal(address, db.address.toString())
|
||||
assert.equal(total, entryCount)
|
||||
|
||||
const { progress, max } = db.replicationStatus
|
||||
assert.equal(max, entryCount)
|
||||
assert.equal(progress, count)
|
||||
|
||||
assert.notEqual(hash, null)
|
||||
assert.notEqual(entry, null)
|
||||
if (progress === entryCount && count === entryCount) {
|
||||
|
||||
@@ -172,9 +172,9 @@ Object.keys(testAPIs).forEach(API => {
|
||||
count: eventCount['replicate.progress'],
|
||||
entry: entry ,
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -185,9 +185,9 @@ Object.keys(testAPIs).forEach(API => {
|
||||
event: 'replicated',
|
||||
count: eventCount['replicate'],
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
// Resolve with a little timeout to make sure we
|
||||
@@ -279,7 +279,7 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
db2.events.on('replicate', (address, entry) => {
|
||||
eventCount['replicate'] ++
|
||||
total = db2._replicationInfo.max
|
||||
total = db2.replicationStatus.max
|
||||
// console.log("[replicate] ", '#' + eventCount['replicate'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished)
|
||||
events.push({
|
||||
event: 'replicate',
|
||||
@@ -290,24 +290,24 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
db2.events.on('replicate.progress', (address, hash, entry) => {
|
||||
eventCount['replicate.progress'] ++
|
||||
current = db2._replicationInfo.progress
|
||||
current = db2.replicationStatus.progress
|
||||
// console.log("[progress] ", '#' + eventCount['replicate.progress'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished)
|
||||
// assert.equal(db2._replicationInfo.progress, eventCount['replicate.progress'])
|
||||
// assert.equal(db2.replicationStatus.progress, eventCount['replicate.progress'])
|
||||
events.push({
|
||||
event: 'replicate.progress',
|
||||
count: eventCount['replicate.progress'],
|
||||
entry: entry ,
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
db2.events.on('replicated', (address, length) => {
|
||||
eventCount['replicated'] += length
|
||||
current = db2._replicationInfo.progress
|
||||
current = db2.replicationStatus.progress
|
||||
// console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d)
|
||||
assert.equal(current, eventCount['replicated'])
|
||||
assert.equal(total, expectedEventCount)
|
||||
@@ -323,9 +323,9 @@ Object.keys(testAPIs).forEach(API => {
|
||||
event: 'replicated',
|
||||
count: eventCount['replicate'],
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
// Resolve with a little timeout to make sure we
|
||||
@@ -419,8 +419,8 @@ Object.keys(testAPIs).forEach(API => {
|
||||
|
||||
db2.events.on('replicate', (address, entry) => {
|
||||
eventCount['replicate'] ++
|
||||
current = db2._replicationInfo.progress
|
||||
total = db2._replicationInfo.max
|
||||
current = db2.replicationStatus.progress
|
||||
total = db2.replicationStatus.max
|
||||
// console.log("[replicate] ", '#' + eventCount['replicate'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished)
|
||||
events.push({
|
||||
event: 'replicate',
|
||||
@@ -432,8 +432,8 @@ Object.keys(testAPIs).forEach(API => {
|
||||
let prevProgress = 0
|
||||
db2.events.on('replicate.progress', (address, hash, entry) => {
|
||||
eventCount['replicate.progress'] ++
|
||||
current = db2._replicationInfo.progress
|
||||
total = db2._replicationInfo.max
|
||||
current = db2.replicationStatus.progress
|
||||
total = db2.replicationStatus.max
|
||||
// console.log("[progress] ", '#' + eventCount['replicate.progress'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished)
|
||||
// assert.equal(current, total)
|
||||
events.push({
|
||||
@@ -441,17 +441,17 @@ Object.keys(testAPIs).forEach(API => {
|
||||
count: eventCount['replicate.progress'],
|
||||
entry: entry ,
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
db2.events.on('replicated', (address, length) => {
|
||||
eventCount['replicated'] += length
|
||||
current = db2._replicationInfo.progress
|
||||
total = db2._replicationInfo.max
|
||||
current = db2.replicationStatus.progress
|
||||
total = db2.replicationStatus.max
|
||||
const values = db2.iterator({limit: -1}).collect()
|
||||
// console.log(current, "/", total, "/", values.length)
|
||||
// console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d)
|
||||
@@ -460,14 +460,14 @@ Object.keys(testAPIs).forEach(API => {
|
||||
event: 'replicated',
|
||||
count: eventCount['replicate'],
|
||||
replicationInfo: {
|
||||
max: db2._replicationInfo.max,
|
||||
progress: db2._replicationInfo.progress,
|
||||
have: db2._replicationInfo.have,
|
||||
max: db2.replicationStatus.max,
|
||||
progress: db2.replicationStatus.progress,
|
||||
have: db2.replicationStatus.have,
|
||||
},
|
||||
})
|
||||
|
||||
if (db2._replicationInfo.max >= expectedEventCount * 2
|
||||
&& db2._replicationInfo.progress >= expectedEventCount * 2)
|
||||
if (db2.replicationStatus.max >= expectedEventCount * 2
|
||||
&& db2.replicationStatus.progress >= expectedEventCount * 2)
|
||||
finished = true
|
||||
})
|
||||
|
||||
|
||||
103
test/replication-status.test.js
Normal file
103
test/replication-status.test.js
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const mapSeries = require('p-map-series')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const rmrf = require('rimraf')
|
||||
const levelup = require('levelup')
|
||||
const leveldown = require('leveldown')
|
||||
const OrbitDB = require('../src/OrbitDB')
|
||||
const OrbitDBAddress = require('../src/orbit-db-address')
|
||||
|
||||
// Include test utilities
|
||||
const {
|
||||
config,
|
||||
startIpfs,
|
||||
stopIpfs,
|
||||
testAPIs,
|
||||
} = require('./utils')
|
||||
|
||||
const dbPath1 = './orbitdb/tests/create-open/1'
|
||||
const dbPath2 = './orbitdb/tests/create-open/2'
|
||||
const ipfsPath = './orbitdb/tests/create-open/ipfs'
|
||||
|
||||
Object.keys(testAPIs).forEach(API => {
|
||||
describe(`orbit-db - Load (${API})`, function() {
|
||||
this.timeout(config.timeout)
|
||||
|
||||
let ipfsd, ipfs, orbitdb1, orbitdb2, db, address
|
||||
let localDataPath
|
||||
|
||||
before(async () => {
|
||||
config.daemon1.repo = ipfsPath
|
||||
rmrf.sync(config.daemon1.repo)
|
||||
rmrf.sync(dbPath1)
|
||||
rmrf.sync(dbPath2)
|
||||
ipfsd = await startIpfs(API, config.daemon1)
|
||||
ipfs = ipfsd.api
|
||||
orbitdb1 = new OrbitDB(ipfs, dbPath1)
|
||||
orbitdb2 = new OrbitDB(ipfs, dbPath2)
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
if(orbitdb1)
|
||||
await orbitdb1.stop()
|
||||
|
||||
if(orbitdb2)
|
||||
await orbitdb2.stop()
|
||||
|
||||
if (ipfsd)
|
||||
await stopIpfs(ipfsd)
|
||||
})
|
||||
|
||||
describe('Replication Status', function() {
|
||||
before(async () => {
|
||||
db = await orbitdb1.log('replication status tests')
|
||||
})
|
||||
|
||||
it('has correct initial state', async () => {
|
||||
assert.deepEqual(db.replicationStatus, { buffered: 0, queued: 0, progress: 0, max: 0 })
|
||||
})
|
||||
|
||||
it('has correct replication info after load', async () => {
|
||||
await db.add('hello')
|
||||
await db.close()
|
||||
await db.load()
|
||||
assert.deepEqual(db.replicationStatus, { buffered: 0, queued: 0, progress: 1, max: 1 })
|
||||
})
|
||||
|
||||
it('has correct replication info after close', async () => {
|
||||
await db.close()
|
||||
assert.deepEqual(db.replicationStatus, { buffered: 0, queued: 0, progress: 0, max: 0 })
|
||||
})
|
||||
|
||||
it('has correct replication info after sync', async () => {
|
||||
await db.load()
|
||||
await db.add('hello2')
|
||||
assert.deepEqual(db.replicationStatus, { buffered: 0, queued: 0, progress: 2, max: 2 })
|
||||
|
||||
const db2 = await orbitdb2.log(db.address.toString(), { create: false, sync: false })
|
||||
await db2.sync(db._oplog.heads)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
assert.deepEqual(db2.replicationStatus, { buffered: 0, queued: 0, progress: 2, max: 2 })
|
||||
resolve()
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
|
||||
it('has correct replication info after loading from snapshot', async () => {
|
||||
await db.saveSnapshot()
|
||||
await db.close()
|
||||
await db.loadFromSnapshot()
|
||||
assert.deepEqual(db.replicationStatus, { buffered: 0, queued: 0, progress: 2, max: 2 })
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user