How server test execution time went from 13 to 2 minutes!⚡

Hello everyone, and especially @contributors for this slightly more technical post than usual!

You won’t believe it, I managed to reduce the server test execution time by 80%, i.e. 5 times faster than before… :sweat_smile:

No more 13 MINUTES of waiting :grimacing:

I had long suspected something was off, but I ended up finding where it was a bit by chance.

Basically, between each test, we run a beforeEach function that takes care of emptying and then filling the DB.

That’s normal, between each test we want the DB to be completely clean so that the tests are independent from each other.

This beforeEach is executed 1,800 times, since we have 1,800 tests in Gladys…

So the slightest optimization on this function gives us an x1800 win…

Diving into the code of these two functions « cleanDb » and « seedDb », I come across this:

I’m quite surprised that there’s a function « callLater » that literally adds a 10ms sleep between each clean/fill of each seed :thinking:

Considering we empty/fill 16 tables during the tests, there is 16 * 10 ms * 2 = 320 ms of idle time, between each test!! :melting_face:

Over 1800 tests, that’s 1800 * 320 = 576 seconds = 9.6 minutes!

At that point, I start sweating bullets, all that time wasted… ^^

I try replacing that bit of code with this:

A more optimized version, without waiting.

And the result is clear:

There’s still work to do

So the test execution time has been greatly reduced, but there’s still a big chunk to shrink: the dependency installation time on CI, which is a very large piece:

Despite the npm cache, dependency installation takes almost 11 minutes, which is far too long.

Certain packages are compiled at each installation and take an insane amount of time to compile, notably open-zwave-shared (which will soon be removed), and node-webcrypto-ossl which will also be removed when we move to Node.js 16, because this library is now integrated into Node.js.

I can’t wait!

6 Likes

@Romuald_Pochet I took the liberty of rebasing your PR onto ZwaveJS2mqtt so your development will be faster :slight_smile: Remember to pull locally and tell me if you notice a difference!

:+1:
I didn’t understand everything, but well done and thanks for all the work.

1 Like