mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-19 16:15:09 +00:00
retry condition moved to startretryloop
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
This commit is contained in:
parent
b8509490ad
commit
5bea58e501
3 changed files with 17 additions and 32 deletions
|
|
@ -10,7 +10,6 @@ import * as redis from '../redis';
|
|||
*/
|
||||
jest.mock('../config');
|
||||
|
||||
|
||||
describe('Testing retryTransaction', () => {
|
||||
let contract: any = null;
|
||||
const transaction = {
|
||||
|
|
@ -20,17 +19,15 @@ describe('Testing retryTransaction', () => {
|
|||
deserializeTransaction: jest.fn().mockReturnValue(transaction),
|
||||
};
|
||||
beforeAll(async () => {
|
||||
const rejectableGetContract = jest.fn().mockImplementation(
|
||||
() =>
|
||||
mockedContact
|
||||
);
|
||||
const rejectableGetContract = jest
|
||||
.fn()
|
||||
.mockImplementation(() => mockedContact);
|
||||
|
||||
const network = getMockedNetwork(rejectableGetContract)('');
|
||||
contract = (await network).getContract('');
|
||||
|
||||
});
|
||||
|
||||
describe('Check retry condition ', () => {
|
||||
describe('Check retry increment ', () => {
|
||||
const transactionId =
|
||||
'0ae62c01e4c4b112c3f3954a2f11243da76778e46df9ad2783bcbafc79652b95';
|
||||
const key = `txn:${transactionId}`;
|
||||
|
|
@ -66,7 +63,7 @@ describe('Testing retryTransaction', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
it('Transaction should exist if retry count is less then max rety count', async () => {
|
||||
it('retry count should incremnt to 4', async () => {
|
||||
savedTransaction.retries = '3';
|
||||
data = { [key]: savedTransaction };
|
||||
await retryTransaction(
|
||||
|
|
@ -82,16 +79,5 @@ describe('Testing retryTransaction', () => {
|
|||
args: args,
|
||||
});
|
||||
});
|
||||
it('Clear transaction once retry reaches max retry count ', async () => {
|
||||
savedTransaction.retries = '5';
|
||||
data = { [key]: savedTransaction };
|
||||
await retryTransaction(
|
||||
contract,
|
||||
redis.redis,
|
||||
transactionId,
|
||||
savedTransaction
|
||||
);
|
||||
expect(data[key]).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export const retryDelay = env
|
|||
.example('3000')
|
||||
.asIntPositive();
|
||||
|
||||
export const maxRetryCount = env
|
||||
export const maxRetryCount = env
|
||||
.get('MAX_RETRY_COUNT')
|
||||
.default('5')
|
||||
.example('5')
|
||||
|
|
|
|||
|
|
@ -136,13 +136,16 @@ export const startRetryLoop = (contract: Contract, redis: Redis): void => {
|
|||
const savedTransaction = await (redis as Redis).hgetall(
|
||||
`txn:${transactionId}`
|
||||
);
|
||||
|
||||
await retryTransaction(
|
||||
contract,
|
||||
redis,
|
||||
transactionId,
|
||||
savedTransaction
|
||||
);
|
||||
if (parseInt(savedTransaction.retries) >= config.maxRetryCount) {
|
||||
await clearTransactionDetails(redis, transactionId);
|
||||
} else {
|
||||
await retryTransaction(
|
||||
contract,
|
||||
redis,
|
||||
transactionId,
|
||||
savedTransaction
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO just log?
|
||||
|
|
@ -283,11 +286,7 @@ export const retryTransaction = async (
|
|||
savedTransaction.retries,
|
||||
transactionId
|
||||
);
|
||||
if (parseInt(savedTransaction.retries) < config.maxRetryCount) {
|
||||
await incrementRetryCount(redis, transactionId);
|
||||
} else {
|
||||
await clearTransactionDetails(redis, transactionId);
|
||||
}
|
||||
await incrementRetryCount(redis, transactionId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue