Open fgblomqvist opened 2 years ago
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 :thinking:
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.