firebase/quickstart-nodejs

RealtimeDB getting timeouts from local database during testing

manbach opened this issue · 4 comments

I tried using the quickstart guide to write test for my realtime database. After about 100 write and read requests (about 20 test cases) in a short time all following tests fail with a timeout of 10 seconds. If i delay some of the tests (about 5 seconds every 20 tests) it works.
So it seems like the local emulator for the firebase Realtime DB blocks my connection. But this seems kind of weird, blocking the own localhost connection. The test are all find, i tried swapping the test order and it allways fails after a set amout.
Is there a way to change the emulator behavior so that i dont have to delay my tests ?

There is no emulator output:
xyz:jutta_firebase_functions xyz$ firebase serve --only database 11:52:04.212 [NamespaceSystem-akka.actor.default-dispatcher-2] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started 11:52:04.337 [main] INFO com.firebase.server.forge.App$ - Listening on port 9000

I found out the problem was with createing new Apps using initializeTestApp or initializeAdminApp. I did everything the same as in the example which resulted into creating new Apps for every test. But it seems that the emulator does not like that and just didnt accept new Apps after i created about a hundred. I now create new apps in the beforeAll part and reuse them in all test and it works fine.

Is there a known limitation that should be noted in the docs ?

@ryanpbrewster is there some limitation or scaling issue with having too many test apps?

Aha! I've been wondering if this would cause an issue.

The emulator treats every project as though it were on the Spark (free) billing plan. For free projects we limit database instances to 100 active connections (reference).

A few ways to work around this:

  • reuse or drop connections between tests (maybe an afterEach block in Mocha that does `Promise.all(firebase.apps().map(app => app.delete()));)
  • use multiple projects (maybe a new project for each test?)

EDIT: Ah, I see you've diagnosed this issue yourself, good solution :)

I've submitted a change to the documentation, should go out with the next update. Thanks for the report!