jehy / telegram-test-api

Simple implimentation of telegram API which can be used for testing telegram bots
MIT License
98 stars 24 forks source link

StoreTimeout hangs issue #20

Closed skif48 closed 5 years ago

skif48 commented 5 years ago

Hi, thanks for this awesome thing! Seems like I found a bug with storeTimeout. I'm using Jest and have the following hooks:

 beforeAll(async () => {
    const serverConfig = {
      port: 9000,
      host: 'localhost',
      storage: 'RAM',
      storeTimeout: 10,
    };

    tgServer = new TelegramServer(serverConfig);

    await tgServer.start();
  });

  afterAll(async () => {
    await tgServer.stop();
  });

I keep getting such errors:

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.

I found an issue here, which is 1.5 years old, about the fact that it takes time for express to stop and that it was fixed in v1.0.1. However, the amount of time Jest has to wait is actually equal to the amount of seconds I provide to storeTimeout key of server configs. I opened the sources and found out that you're using bluebird's Promise.delay(), which uses setTimeout() under the hood. Most likely the event loop is not empty even after you stop the server, since it has a scheduled callback to execute.

Thanks!

jehy commented 5 years ago

Should be fixed in version 2.4.2.