Skip to content

Commit

Permalink
Increase timeouts for tip height waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Oct 24, 2021
1 parent ea100fb commit 12b7be7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
1 change: 1 addition & 0 deletions integration_tests/features/Sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Feature: Block Sync
| 1000 | 50 |
| 1001 | 50 |

@doit
Scenario: Pruned mode network only
Given I have a base node NODE1 connected to all seed nodes
Given I have a pruned node PNODE1 connected to node NODE1 with pruning horizon set to 5
Expand Down
41 changes: 18 additions & 23 deletions integration_tests/features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
consoleLogBalance,
consoleLogTransactionDetails,
withTimeout,
waitForIterate,
} = require("../../helpers/util");
const { ConnectivityStatus, PaymentType } = require("../../helpers/types");
const TransactionBuilder = require("../../helpers/transactionBuilder");
Expand Down Expand Up @@ -828,24 +829,21 @@ When(/I stop node (.*)/, async function (name) {
await this.stopNode(name);
});

Then(
/node (.*) is at height (\d+)/,
{ timeout: 120 * 1000 },
async function (name, height) {
const client = this.getClient(name);
await waitForPredicate(
async () => (await client.getTipHeight()) === height,
115 * 1000
);
const currentHeight = await client.getTipHeight();
console.log(
`Node ${name} is at tip: ${currentHeight} (should be`,
height,
`)`
);
expect(currentHeight).to.equal(height);
}
);
Then(/node (.*) is at height (\d+)/, async function (name, height) {
const client = this.getClient(name);
const currentHeight = await waitForIterate(
() => client.getTipHeight(),
height,
1000,
200
);
console.log(
`Node ${name} is at tip: ${currentHeight} (should be`,
height,
`)`
);
expect(currentHeight).to.equal(height);
});

Then(
/node (.*) has a pruned height of (\d+)/,
Expand Down Expand Up @@ -900,10 +898,7 @@ Then(
async function (height) {
let tipHash = null;
await this.forEachClientAsync(async (client, name) => {
await waitForPredicate(
async () => (await client.getTipHeight()) === height,
115 * 1000
);
await waitForIterate(() => client.getTipHeight(), height, 200 * 1000);
const currTip = await client.getTipHeader();
console.log(
`${client.name} is at tip ${currTip.height} (${currTip.hash.toString(
Expand Down Expand Up @@ -994,7 +989,7 @@ Then(
async function (node) {
const client = this.getClient(node);
await waitForPredicate(
async () => (await client.initial_sync_achieved()) === true,
async () => await client.initial_sync_achieved(),
20 * 60 * 1000,
1000
);
Expand Down
7 changes: 4 additions & 3 deletions integration_tests/helpers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ async function waitFor(

async function waitForIterate(testFn, toBe, sleepMs, maxIterations = 500) {
let count = 0;
let val = testFn();
while (!(val === toBe)) {
val = testFn();
let val = await Promise.resolve(testFn());
while (val !== toBe) {
val = await Promise.resolve(testFn());
if (count >= maxIterations) {
break;
}
count++;
await sleep(sleepMs);
process.stdout.write(".");
}
return val;
}

async function waitForPredicate(predicate, timeOut, sleepMs = 500) {
Expand Down

0 comments on commit 12b7be7

Please sign in to comment.