Skip to content

Commit 8df9845

Browse files
committed
perf: extra delays on wallet start
1 parent 8ebd1e0 commit 8df9845

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

__tests__/integration/multisig.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ describe('send tx (HTR)', () => {
9292
wallet5 = new WalletHelper('multisig-5', { seedKey: 'multisig-5', multisig: true });
9393
walletExtra = new WalletHelper('multisig-extra', { seedKey: 'multisig-extra', multisig: true });
9494

95-
await WalletHelper.startMultipleWalletsForTest([
96-
wallet1, wallet2, wallet3, wallet4, wallet5, walletExtra],
97-
{ serial: true });
95+
await WalletHelper.startMultipleWalletsForTest(
96+
[wallet1, wallet2, wallet3, wallet4, wallet5, walletExtra]
97+
);
9898

9999
// Funds for single input/output tests
100100
const fundTxObj1 = await wallet1.injectFunds(1000, 0);

__tests__/integration/send-tx.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ describe('send tx (custom tokens)', () => {
672672
wallet5 = new WalletHelper('custom-tx-5');
673673

674674
await WalletHelper.startMultipleWalletsForTest(
675-
[wallet1, wallet2, wallet3, wallet4, wallet5],
676-
{ serial: true }
675+
[wallet1, wallet2, wallet3, wallet4, wallet5]
677676
);
678677

679678
// Funds for single input/output tests - 1000 HTR + 2000 custom A

__tests__/integration/utils/test-utils-integration.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export class TestUtils {
140140
* @returns {Promise<{start:unknown,status:unknown}>}
141141
*/
142142
static async startWallet(walletObj, options = {}) {
143+
const requestStart = Date.now().valueOf();
144+
143145
let response;
144146
// Request the Wallet start
145147
if (walletObj.words) {
@@ -156,6 +158,12 @@ export class TestUtils {
156158
});
157159
}
158160

161+
const requestEnd = Date.now().valueOf();
162+
TestUtils.logTx('Wallet start requested', {
163+
walletId: walletObj.walletId,
164+
requestDuration: requestEnd - requestStart
165+
})
166+
159167
// Handle errors
160168
if (response.status !== 200) {
161169
throw new Error(`Unable to start the wallet: ${walletObj.walletId}`);
@@ -175,6 +183,12 @@ export class TestUtils {
175183
}
176184
await TestUtils.delay(1000);
177185
}
186+
187+
const readyEnd = Date.now().valueOf()
188+
TestUtils.logTx('Wallet is ready', {
189+
walletId: walletObj.walletId,
190+
waitForReadyDuration: readyEnd - requestEnd
191+
})
178192
}
179193
// Log the success and return
180194
if (walletObj.words) {

__tests__/integration/utils/wallet-helper.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ export class WalletHelper {
128128
* performance-wise.
129129
* @param {WalletHelper[]} walletsArr Array of WalletHelpers
130130
* @param [options]
131-
* @param {boolean} [options.skipAddresses] Skips the getSomeAddresses command
132-
* @param {number} [options.amountOfAddresses=10] How many addresses should be cached per wallet
133131
* @param {boolean} [options.serial] Start one wallet at a time
134132
* @returns {Promise<void>}
135133
*/
136-
static async startMultipleWalletsForTest(walletsArr, options) {
134+
static async startMultipleWalletsForTest(walletsArr, options = {}) {
137135
/**
138136
* A map of `WalletHelper`s indexed by their `walletId`s
139137
* @type {Record<string,WalletHelper>}
@@ -147,30 +145,29 @@ export class WalletHelper {
147145
walletsArr.unshift(new WalletHelper(genesis.walletId, { words: genesis.words }));
148146
}
149147

150-
// If we need to initialize too many wallets at once, it's better to do it serially
151-
if (options.serial) {
148+
if (options.serial || walletsArr.length > 2) {
149+
// If we need to initialize too many wallets at once, it's better to do it serially
152150
for (const wallet of walletsArr) {
153151
TestUtils.logTx('Requesting serial wallet init', {
154152
walletId: wallet.walletId
155153
})
156154
await TestUtils.startWallet(wallet.walletData, {
157155
waitWalletReady: true
158156
});
157+
walletsPendingReady[wallet.walletId] = wallet;
159158
}
160-
161-
// Finish the function here
162-
await TestUtils.pauseForWsUpdate();
163-
return;
164159
}
165-
166-
// Requests the start of all the wallets in quick succession - parallel mode
167-
const startPromisesArray = [];
168-
for (const wallet of walletsArr) {
169-
const promise = TestUtils.startWallet(wallet.walletData);
170-
walletsPendingReady[wallet.walletId] = wallet;
171-
startPromisesArray.push(promise);
160+
else {
161+
// Requests the start of all the wallets in quick succession - parallel mode
162+
TestUtils.logTx('Requesting batch wallet init', { amount: walletsArr.length });
163+
const startPromisesArray = [];
164+
for (const wallet of walletsArr) {
165+
const promise = TestUtils.startWallet(wallet.walletData);
166+
walletsPendingReady[wallet.walletId] = wallet;
167+
startPromisesArray.push(promise);
168+
}
169+
await Promise.all(startPromisesArray);
172170
}
173-
await Promise.all(startPromisesArray);
174171

175172
// Enters the loop checking each wallet for its status
176173
const timestampStart = Date.now().valueOf();

0 commit comments

Comments
 (0)