test: add utility to wait for values
This commit is contained in:
parent
bb797602e6
commit
b37ac59973
@ -16,6 +16,7 @@ const FullNode = require('../lib/node/fullnode');
|
||||
const Network = require('../lib/protocol/network');
|
||||
const network = Network.get('regtest');
|
||||
const {NodeClient, WalletClient} = require('bclient');
|
||||
const {forValue} = require('./util/common');
|
||||
|
||||
const workers = new WorkerPool({
|
||||
enabled: true
|
||||
@ -297,6 +298,8 @@ describe('Indexer', function() {
|
||||
assert.equal(blocks.length, 1);
|
||||
}
|
||||
|
||||
await forValue(node.chain, 'height', 160);
|
||||
|
||||
// Send unconfirmed to the vector addresses.
|
||||
for (let i = 0; i < 3; i++) {
|
||||
for (const v of vectors) {
|
||||
@ -306,6 +309,8 @@ describe('Indexer', function() {
|
||||
unconfirmed.push(txid);
|
||||
}
|
||||
}
|
||||
|
||||
await forValue(node.mempool.map, 'size', 6);
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
|
||||
@ -102,6 +102,27 @@ common.rimraf = async function(p) {
|
||||
return await fs.rimraf(p);
|
||||
};
|
||||
|
||||
common.forValue = async function(obj, key, val, timeout = 60000) {
|
||||
assert(typeof obj === 'object');
|
||||
assert(typeof key === 'string');
|
||||
|
||||
const ms = 10;
|
||||
let interval = null;
|
||||
let count = 0;
|
||||
return new Promise((resolve, reject) => {
|
||||
interval = setInterval(() => {
|
||||
if (obj[key] === val) {
|
||||
clearInterval(interval);
|
||||
resolve();
|
||||
} else if (count * ms >= timeout) {
|
||||
clearInterval(interval);
|
||||
reject(new Error('Timeout waiting for value.'));
|
||||
}
|
||||
count += 1;
|
||||
}, ms);
|
||||
});
|
||||
};
|
||||
|
||||
function parseUndo(data) {
|
||||
const br = bio.read(data);
|
||||
const items = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user