我用 qldb 设置了我的 nodejs 应用程序来实现钱包服务。使用一些成功测试和一些预期的错误测试设置一些测试,偶尔会发生此错误“BadRequestException:没有打开的事务”并导致我的测试失败。如果我再次运行测试,它们将通过。偶尔,这个错误会意外发生,导致测试失败。当注释掉我预期的错误测试并且错误没有发生或没有经常发生时,我注意到了。这个错误不仅发生在预期的错误测试中,而且发生在成功的测试中。这就是我的测试的样子
describe('createWallet()', () => {
it('should return an object with wallet Id', async () => {
let result6 = await controller.createWallet({ body: mocks.walletInfo6.info });
documentId6 = result6.walletId;
expect(result6).to.have.property('walletId').that.is.a.uuid;
});
it('One player should have only one active wallet for each currency', async () => {
try {
let res = await controller.createWallet({ body: mocks.walletInfo1.info });
assert.fail('expected error was not thrown')
} catch (e) {
expect(e.message).to.equal('Player already owns an active wallet in this currency.');
}
});
});
describe('suspendWallet()', () => {
it('should change wallet status to suspend', async () => {
let res = await controller.suspendWallet({ documentId: documentId3 });
await controller.suspendWallet({ documentId: documentId5 });
expect(res).to.be.a.string;
expect(res).to.equal(documentId3);
});
it('should not change wallet status if wallet Id is invalid', async () => {
try {
let res = await controller.suspendWallet({ documentId: mocks.invalidWalletId });
assert.fail('expected error was not thrown')
} catch (e) {
expect(e.message).to.equal('Did not find any record with this document Id.');
}
});
});