You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fiddling around with the tests I kept wondering why mocha kept running forever even though all the cases finished. Any test file that imports from the testConfig keep running forever, even if it just just a expect(true).to.eql(true).
I discovered that testConfig imports the Redis adapter from redis-adapter.js and that that file in turn has a side effect of opening a redis connection, no matter what. Furthermore, there is no way to close that connection since the client sits unexported in the global scope.
There are several issues at play here:
The client should not connect to anything on import, that is bad practice.
Instead, make the connection inside the RedisAdapter constructor (why otherwise have a constructor?) and store it on this (rather than globally). If you want a single connection, you can initialize a single instance of this adapter somewhere and pass it around (or at least do a singleton pattern).
It is not possible to close the connection.
Add a method to the adapter that calls the this.client.disconnect() method. Once that is in place, any user of it (such as tests and application code) can now properly close the connection at the end.
The text was updated successfully, but these errors were encountered:
I think cleaning up the Redis adapter is a good idea, but I'm not experiencing the issues with mocha keeping on running forever except that watch mode is on by default. How are you running the tests?
Even with watch mode turned off it happens. I do yarn docker:compose:test:up and then in a separate window yarn test:all. After saying how many passed and skipped it just hangs. Sounds quite odd that our setups are running so differently 🤔
If I run a single test that does not do any DDB stuff, such as the Template.test.js, and after I've fixed the redis client, that test finishes without issues and mocha exits. But yeah, lots of other oddities. If nothing else, it's fascinating debugging this lol.
Fiddling around with the tests I kept wondering why mocha kept running forever even though all the cases finished. Any test file that imports from the
testConfig
keep running forever, even if it just just aexpect(true).to.eql(true)
.I discovered that
testConfig
imports the Redis adapter fromredis-adapter.js
and that that file in turn has a side effect of opening a redis connection, no matter what. Furthermore, there is no way to close that connection since theclient
sits unexported in the global scope.There are several issues at play here:
RedisAdapter
constructor (why otherwise have a constructor?) and store it onthis
(rather than globally). If you want a single connection, you can initialize a single instance of this adapter somewhere and pass it around (or at least do a singleton pattern).this.client.disconnect()
method. Once that is in place, any user of it (such as tests and application code) can now properly close the connection at the end.The text was updated successfully, but these errors were encountered: