Skip to content

Commit

Permalink
fixup! feat(cardano-services): implements rabbitmq new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Jun 20, 2022
1 parent 9def59e commit 90728a8
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions packages/cardano-services/test/load/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ describe('load', () => {
wallet = await getWallet();
({ address } = (await firstValueFrom(wallet.addresses$))[0]);

logger.debug('Waiting to settle wallet status');
await firstValueFrom(wallet.syncStatus.isSettled$.pipe(filter((isSettled) => isSettled)));
logger.debug('Wallet status settled');
};

const waitForTxInBlockchain = (txId: Cardano.TransactionId) =>
Expand All @@ -164,9 +166,9 @@ describe('load', () => {
});

logger.info(`Fragmentation tx: ${tx.hash}`);

await wallet.submitTx(await wallet.finalizeTx(tx));
await waitForTxInBlockchain(tx.hash);
logger.info('Fragmentation completed');
};

if (options.directlyToOgmios) await fragment();
Expand Down Expand Up @@ -220,50 +222,61 @@ describe('load', () => {
afterEach(stopWorker);

const performTest = async (options: TestOptions) => {
const { directlyToOgmios, withRunningWorker } = options;
const { directlyToOgmios, parallel, withRunningWorker } = options;
const submitPromises: Promise<void>[] = [];
const txIds: Cardano.TransactionId[] = [];
let timeAfterWorkerStarted = 0;
let timeBeforeSubmitTxs = 0;

await fragmentWhenRequired(options);
try {
logger.debug(`Starting test with options: ${JSON.stringify({ directlyToOgmios, parallel, withRunningWorker })}`);

const startWorkerForTest = async () => {
if (!directlyToOgmios) await startWorker(options);
timeAfterWorkerStarted = Date.now();
};
await fragmentWhenRequired(options);

const submitTransactions = async () => {
timeBeforeSubmitTxs = Date.now();
for (let i = 0; i < env.TRANSACTIONS_NUMBER; ++i) {
const coins = 1_000_000n + 1000n * BigInt(i);
const tx = await wallet.initializeTx({ outputs: new Set([{ address, value: { coins } }]) });
const startWorkerForTest = async () => {
if (!directlyToOgmios) await startWorker(options);
timeAfterWorkerStarted = Date.now();
};

submitPromises.push(wallet.submitTx(await wallet.finalizeTx(tx)));
txIds.push(tx.hash);
const submitTransactions = async () => {
timeBeforeSubmitTxs = Date.now();
for (let i = 0; i < env.TRANSACTIONS_NUMBER; ++i) {
const coins = 1_000_000n + 1000n * BigInt(i);
const tx = await wallet.initializeTx({ outputs: new Set([{ address, value: { coins } }]) });

submitPromises.push(wallet.submitTx(await wallet.finalizeTx(tx)));
txIds.push(tx.hash);
}
};

if (withRunningWorker) {
await startWorkerForTest();
await submitTransactions();
} else {
await submitTransactions();
await startWorkerForTest();
}
};

if (withRunningWorker) {
await startWorkerForTest();
await submitTransactions();
} else {
await submitTransactions();
await startWorkerForTest();
}
await Promise.all(submitPromises);
const timeAfterTxsInMempool = Date.now();

await Promise.all(submitPromises);
const timeAfterTxsInMempool = Date.now();
await Promise.all(txIds.map((txId) => waitForTxInBlockchain(txId)));

await Promise.all(txIds.map((txId) => waitForTxInBlockchain(txId)));
testReports.push({
...options,
timeAfterTxsInBlockchain: Date.now(),
timeAfterTxsInMempool,
timeAfterWorkerStarted,
timeBeforeSubmitTxs
});

testReports.push({
...options,
timeAfterTxsInBlockchain: Date.now(),
timeAfterTxsInMempool,
timeAfterWorkerStarted,
timeBeforeSubmitTxs
});
logger.debug(`Completed test with options: ${JSON.stringify({ directlyToOgmios, parallel, withRunningWorker })}`);
} catch (error) {
logger.error(
`Failed test with options: ${JSON.stringify({ directlyToOgmios, parallel, withRunningWorker })}`,
error
);
}
};

describe('directly to ogmios', () => {
Expand Down

0 comments on commit 90728a8

Please sign in to comment.