Transcript
00:00 Debugging anything has to start from somewhere, and performance issues in your test is not an exception. Well, how can you improve it if you don't even know what to improve or where to look at? You need a roadmap that will eventually lead you to the thing or things that make your test slow. In this exercise, we're going to talk about how you can approach any performance degradation
00:17 methodically by using profiling, and to do that, we're going to take a look at a slow test. So if I run my test right now, I will see that it takes more than a second to run them, and it shouldn't be like that. This is a very straightforward test, and I think it should be much faster, but let's
00:33 take a closer look at this test summary from VTEST to plan out our debugging strategy. So first of all, we are interested in this duration line over here. It contains the total time it took VTEST to run our tests, and also a detailed breakdown of how much time each individual test phase took. So let's take a closer look at those test phases.
00:51 First we have this transform phase that is responsible for transforming your test files. So in my case, I have my test written in TypeScript. So VTEST will transpile TypeScript into JavaScript and then run my tests. In this case, it took 18 milliseconds, which was pretty fast. The setup phase is when VTEST applies your test setup, and since I happen to have none
01:09 in this situation, it was 0 milliseconds. The collect phase is when VTEST collects the test files from the file system, basically analyzes which files match the test patterns that you define in the VTEST config, and here it was pretty fast as well. Then the test phase is how long it took to run the actual test cases, and here I can
01:27 see it took 851 milliseconds, which is a huge percentage from the total test run. And already I know that this will probably be the area I will be debugging. But let's break down other test phases as well. The environment phase that follows is how much time it took VTEST to spin up your test environment.
01:44 So if you're using a custom test environment and it is slow, this is the metric you should watch out for. And finally, the preparation phase is how much time it took VTEST to prepare the test runner. So in my case, it was also pretty fast. So even from this test summary, you can see that the root cause for this performance degradation is likely in the tests themselves.
02:03 And your task in this exercise is to find that root cause. But this summary alone is not enough. You have to dive deeper. You'll be using a third-party package called VTEST Profiler to generate CPU and memory profiles of your test run, and then analyze those profiles to locate the culprit. You don't have to fix it, only to find it.
02:20 So give it your best, and once you're done, come back to me so we can talk about test profiling in more detail.