pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

pg-mem doesn't seem to work in conjunction with sinon fake timers

Open abadyan-vonage opened this issue 4 years ago • 3 comments

Describe the bug

I am trying to run a test that uses a fake timer in order to reliably check the output. The query works just fine without fake timers, but when I do:

const initialExpiration = new Date();
sinon.useFakeTimers(initialExpiration);

The query never returns and my test times out.

To Reproduce

SELECT count(*) FROM my_table WHERE owner=$1 and object_type=$2 and code IS NOT NULL;

pg-mem version

2.0.1

Thanks a lot for taking the time to support this project, it's very helpful!

abadyan-vonage avatar Nov 01 '21 09:11 abadyan-vonage

Found a workaround for this. sinon allows you to only fake some of the methods so I used this form:

sinon.useFakeTimers({ now: initialExpiration, toFake: ['Date'] });

I guess pg-mem relies on some of the other date related functions somewhere and this allows us to avoid it. Further information: https://sinonjs.org/releases/latest/fake-timers/

abadyan-vonage avatar Nov 01 '21 09:11 abadyan-vonage

Hi ! Thanks for the report.

Should be fixed with [email protected]

oguimbal avatar Nov 01 '21 10:11 oguimbal

Still happening with 2.1.9.

abadyan-vonage avatar Nov 01 '21 11:11 abadyan-vonage