Skip to content

Commit

Permalink
Improve tester-service in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Nov 1, 2024
1 parent 926822b commit 87da2e6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project contains end-to-end (E2E) tests for peer-to-peer (P2P) syncing with

| From \ To | Juno | Pathfinder | Papyrus | Madara |
|------------|------|------------|---------|--------|
| Juno || |||
| Juno || |||
| Pathfinder |||||
| Papyrus |||||
| Madara |||||
Expand Down
64 changes: 44 additions & 20 deletions e2e/tester/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,86 @@ const timeout = parseInt(process.argv[3], 10);
const targetBlockNumber = parseInt(process.argv[4], 10);

function log(message) {
console.log(message);
if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
process.stdout.write(''); // Force flush
}
process.stdout.write(`[${new Date().toISOString()}] ${message}\n`);
}

async function waitForNodeReady(maxAttempts = 30, interval = 10000) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
await node.getBlockLatestAccepted();
log("Node is ready.");
log("Node is ready");
return true;
} catch (error) {
log(`Waiting for node to be ready... (Attempt ${attempt + 1}/${maxAttempts})`);
log(`Waiting for node... (${attempt + 1}/${maxAttempts})`);
await new Promise(resolve => setTimeout(resolve, interval));
}
}
log("Node failed to become ready in time.");
log("Node failed to become ready in time");
return false;
}

async function syncNode() {
log(`Syncing to target block: ${targetBlockNumber}`);
log(`➜ Starting sync to target block ${targetBlockNumber}`);

const nodeReady = await waitForNodeReady();
if (!nodeReady) {
if (!await waitForNodeReady()) {
process.exit(1);
}

const startTime = Date.now();
let lastBlockTime = Date.now();
let lastBlockNumber;

const timer = setInterval(async () => {
try {
const startBlock = await node.getBlockLatestAccepted();
lastBlockNumber = startBlock.block_number;
log(`➜ Initial block: ${lastBlockNumber}`);
} catch (error) {
log(`✗ Failed to get initial block: ${error.message}`);
process.exit(1);
}

const checkSync = setInterval(async () => {
try {
const currentBlock = await node.getBlockLatestAccepted();
log(`Current syncing block: ${currentBlock.block_number}`);
const elapsedMinutes = (Date.now() - startTime) / 1000 / 60;
const blocksSynced = currentBlock.block_number - lastBlockNumber;

// Update progress
if (currentBlock.block_number > lastBlockNumber) {
const speed = blocksSynced / elapsedMinutes;
log(`↑ Block ${currentBlock.block_number} | +${blocksSynced} blocks | ${elapsedMinutes.toFixed(1)}m | ${speed.toFixed(1)} blocks/min`);
lastBlockNumber = currentBlock.block_number;
lastBlockTime = Date.now();
}

// Check completion
if (currentBlock.block_number >= targetBlockNumber) {
log(`Syncing node has reached or surpassed the target block ${targetBlockNumber}.`);
log("Sync successful. Stopping checks.");
clearInterval(timer);
const totalMinutes = (Date.now() - startTime) / 1000 / 60;
log(`\n✓ Sync completed in ${totalMinutes.toFixed(1)} minutes`);
clearInterval(checkSync);
process.exit(0);
}

// Check timeouts
const noProgressTime = (Date.now() - lastBlockTime) / 1000 / 60;
if (noProgressTime >= 5) {
log(`\n✗ Sync stalled - No progress for ${noProgressTime.toFixed(1)} minutes`);
clearInterval(checkSync);
process.exit(1);
}

if (Date.now() - startTime > timeout * 1000) {
log(`Timeout of ${timeout} seconds reached. Sync unsuccessful.`);
clearInterval(timer);
log(`\n✗ Sync timeout after ${timeout} seconds`);
clearInterval(checkSync);
process.exit(1);
}
} catch (error) {
log(`Error during sync check: ${error.message}`);
// Instead of exiting immediately, we'll continue the loop
log(`! Error checking sync: ${error.message}`);
}
}, 10000);
}

syncNode().catch(error => {
log(`Unhandled error occurred: ${error.message}`);
log(`✗ Fatal error: ${error.message}`);
process.exit(1);
});
2 changes: 1 addition & 1 deletion e2e/tests/sync/juno_from_juno.star
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
participants = import_module("../../clients/participants.star")

# Test configuration
SYNC_TIMEOUT_SECONDS = 600
SYNC_TIMEOUT_SECONDS = 1200
TARGET_BLOCK_NUMBER = 1000

def run(plan):
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/sync/juno_from_pathfinder.star
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
participants = import_module("../../clients/participants.star")

# Test configuration
SYNC_TIMEOUT_SECONDS = 600
SYNC_TIMEOUT_SECONDS = 1200
TARGET_BLOCK_NUMBER = 1000

def run(plan):
Expand Down

0 comments on commit 87da2e6

Please sign in to comment.