woodser / monero-ts

TypeScript library for using Monero
http://woodser.github.io/monero-ts/typedocs
MIT License
198 stars 67 forks source link

rpc calls create unresolved timeouts/promises until HttpClient.DEFAULT_TIMEOUT as such jest tests warning #172

Closed opx221 closed 5 months ago

opx221 commented 5 months ago

Hello again

Also problem I experienced is that HttpClient creates unresolved timeouts/promises until HttpClient.DEFAULT_TIMEOUT - timeout check this results in jest tests giving warnings and not exiting properly this can be fixed by settings HttpClient.DEFAULT_TIMEOUT to a low value, for example 1000, or by using the jest --forceExit, or by canceling the unresolved timeout (or was it promise?) on successful result from rpc call

Thank you

woodser commented 5 months ago

The RPC call should resolve as soon as a response is received, or after the default timeout, whichever happens first.

Can you give a specific example of different behavior?

opx221 commented 5 months ago

The RPC call should resolve as soon as a response is received, or after the default timeout, whichever happens first.

Can you give a specific example of different behavior?

the rpc call itself does resolve, but it creates another unresolved timeout or promise for checking the timeout that makes jest complain

Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

jest test demonstrating this

import { HttpClient } from 'monero-ts';
import { connectToWalletRpc } from 'monero-ts';

//HttpClient.DEFAULT_TIMEOUT = 1000;
// uncomment to make jest test exit properly

test('rpc does not leave open handles', async () => {
  const walletRpc = await connectToWalletRpc('http://localhost:18081');
  expect(await walletRpc.getPrimaryAddress()).toBeTruthy();
});
woodser commented 5 months ago

I haven't been able to recreate the issue in a jest project, but are you able to test this commit? https://github.com/woodser/monero-ts/pull/169/commits/c0651ab8d114f06169c0f76d7eb0a9856d0ae054

It cancels the timeout promise on successful response.

Otherwise, maybe you have a project I could check out to recreate?

woodser commented 5 months ago

Fixed with the last release: https://github.com/woodser/monero-ts/commit/96daaa0791b9fe2393f2d0390c8659abc66f6a48