mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +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');
|
jest.mock('../config');
|
||||||
|
|
||||||
|
|
||||||
describe('Testing retryTransaction', () => {
|
describe('Testing retryTransaction', () => {
|
||||||
let contract: any = null;
|
let contract: any = null;
|
||||||
const transaction = {
|
const transaction = {
|
||||||
|
|
@ -20,17 +19,15 @@ describe('Testing retryTransaction', () => {
|
||||||
deserializeTransaction: jest.fn().mockReturnValue(transaction),
|
deserializeTransaction: jest.fn().mockReturnValue(transaction),
|
||||||
};
|
};
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const rejectableGetContract = jest.fn().mockImplementation(
|
const rejectableGetContract = jest
|
||||||
() =>
|
.fn()
|
||||||
mockedContact
|
.mockImplementation(() => mockedContact);
|
||||||
);
|
|
||||||
|
|
||||||
const network = getMockedNetwork(rejectableGetContract)('');
|
const network = getMockedNetwork(rejectableGetContract)('');
|
||||||
contract = (await network).getContract('');
|
contract = (await network).getContract('');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Check retry condition ', () => {
|
describe('Check retry increment ', () => {
|
||||||
const transactionId =
|
const transactionId =
|
||||||
'0ae62c01e4c4b112c3f3954a2f11243da76778e46df9ad2783bcbafc79652b95';
|
'0ae62c01e4c4b112c3f3954a2f11243da76778e46df9ad2783bcbafc79652b95';
|
||||||
const key = `txn:${transactionId}`;
|
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';
|
savedTransaction.retries = '3';
|
||||||
data = { [key]: savedTransaction };
|
data = { [key]: savedTransaction };
|
||||||
await retryTransaction(
|
await retryTransaction(
|
||||||
|
|
@ -82,16 +79,5 @@ describe('Testing retryTransaction', () => {
|
||||||
args: args,
|
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')
|
.example('3000')
|
||||||
.asIntPositive();
|
.asIntPositive();
|
||||||
|
|
||||||
export const maxRetryCount = env
|
export const maxRetryCount = env
|
||||||
.get('MAX_RETRY_COUNT')
|
.get('MAX_RETRY_COUNT')
|
||||||
.default('5')
|
.default('5')
|
||||||
.example('5')
|
.example('5')
|
||||||
|
|
|
||||||
|
|
@ -136,13 +136,16 @@ export const startRetryLoop = (contract: Contract, redis: Redis): void => {
|
||||||
const savedTransaction = await (redis as Redis).hgetall(
|
const savedTransaction = await (redis as Redis).hgetall(
|
||||||
`txn:${transactionId}`
|
`txn:${transactionId}`
|
||||||
);
|
);
|
||||||
|
if (parseInt(savedTransaction.retries) >= config.maxRetryCount) {
|
||||||
await retryTransaction(
|
await clearTransactionDetails(redis, transactionId);
|
||||||
contract,
|
} else {
|
||||||
redis,
|
await retryTransaction(
|
||||||
transactionId,
|
contract,
|
||||||
savedTransaction
|
redis,
|
||||||
);
|
transactionId,
|
||||||
|
savedTransaction
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// TODO just log?
|
// TODO just log?
|
||||||
|
|
@ -283,11 +286,7 @@ export const retryTransaction = async (
|
||||||
savedTransaction.retries,
|
savedTransaction.retries,
|
||||||
transactionId
|
transactionId
|
||||||
);
|
);
|
||||||
if (parseInt(savedTransaction.retries) < config.maxRetryCount) {
|
await incrementRetryCount(redis, transactionId);
|
||||||
await incrementRetryCount(redis, transactionId);
|
|
||||||
} else {
|
|
||||||
await clearTransactionDetails(redis, transactionId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue