talawa-api icon indicating copy to clipboard operation
talawa-api copied to clipboard

Test run time is too long.

Open palisadoes opened this issue 10 months ago • 33 comments

Describe the bug

  1. Test run time is too long.
  2. They are taking 20 minutes to run
  3. This is unacceptable

To Reproduce

  1. Submit a Pull Request
  2. Tests take too long

Expected behavior

  • Much faster execution

Actual behavior

  • See above

Screenshots

  • N/A.

Additional details

  • N/A

Potential internship candidates

Please read this if you are planning to apply for a Palisadoes Foundation internship

  • https://github.com/PalisadoesFoundation/talawa/issues/359

palisadoes avatar Apr 19 '24 22:04 palisadoes

I would like to work on this issue.

lokeshwar777 avatar Apr 20 '24 03:04 lokeshwar777

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

github-actions[bot] avatar May 01 '24 00:05 github-actions[bot]

What can be the approach to solve this? @palisadoes ? What can be the possible reasons for the delay of the tests? I have faced this myself but the solution isnt clear to me. @lokeshwar777 How are you gonna solve this?

Atharva-Kanherkar avatar May 01 '24 08:05 Atharva-Kanherkar

All i found was this article here : Improve test time And a github discussion : Link There is some use of "threads" as vitest is multi threaded.

Atharva-Kanherkar avatar May 01 '24 08:05 Atharva-Kanherkar

Me and Peter discussed about the possible approach. Refer in talawa-projects Slack channel https://thepalisadoes-dyb6419.slack.com/archives/C06NRV8J9A9/p1713548954306069?thread_ts=1713548954.306069&cid=C06NRV8J9A9

varshith257 avatar May 01 '24 13:05 varshith257

Unassigning. No activity

palisadoes avatar May 02 '24 03:05 palisadoes

@varshith257

  1. Please propose a directory structure to handle it.
  2. How can we make the tests in each folder run concurrently?

You proposed splitting the runs into two parallel streams. That would mean hopefully a halving of our 20 minute run time. That's still too long.

image

palisadoes avatar May 02 '24 03:05 palisadoes

@palisadoes Would running the tests for only the files that have been changed work?

karthxk07 avatar May 04 '24 07:05 karthxk07

That's a novel idea. Do other organizations' repos do that?

palisadoes avatar May 04 '24 08:05 palisadoes

@palisadoes Didn't check on that, will research on this and let you know.

karthxk07 avatar May 04 '24 11:05 karthxk07

@palisadoes I couldn't really find anything about this. We wouldn't know what problems, implementing this might bring unless we do it. Can I work on this (with a mentor if possible) ?

karthxk07 avatar May 05 '24 09:05 karthxk07

It's not a good approach and never seen in other orgs of testing changed files only. It makes no sense of testing changed files only. How can we rectify that distrupts other files that has dependency if changed files only tetsed.

Possibile method is making tests files subfolders and adding CI workflow for them to test. If adding two subfolders doesn't meet the less time requirement we need to look for more split of tests into subfolders and triger test workflow for them.

From my observation there are few files that are taking most of the time for testing. Should be focused on them to split.

varshith257 avatar May 05 '24 09:05 varshith257

@varshith257 I was also thinking about it.

How can we rectify that distrupts other files that has dependency if changed files only tetsed.

I found out this in the vitest docs, not sure if it helps

https://vitest.dev/config/#maxconcurrency

karthxk07 avatar May 05 '24 10:05 karthxk07

Ok! Give it a try by creating a small subfolder with 10-15 tests in a folder, using of maxConcurrency variable and check if it works for running tests concurrently. It can be tested locally with a change of pointing directory in the package.json

@karthxk07 Ask here to get assigned this issue

varshith257 avatar May 05 '24 13:05 varshith257

Runtime without maxConcurrency flag(default maxConcurrency =5)

Screenshot from 2024-05-06 19-17-11

Runtime with maxConcurrency=10 and sequence.concurrent flag

image

sequence.concurrent was surely running multiple tests at the same time, but most of them threw errors . This might be because tests are written in sequential order, which have to be run in a particular order only. We might have to scrape this approach. @varshith257 how should i proceed further.

karthxk07 avatar May 06 '24 13:05 karthxk07

Would it make sense to reload test data for every test file to reduce the risk?

palisadoes avatar May 06 '24 15:05 palisadoes

Karthik, Follow the approach I proposed of making subdirectories. Try to split the tests based on the number of tests in each test file and try to equalize them.Start with 2 and let's see how much it reduces time and will further optimise the approach based on it.

varshith257 avatar May 07 '24 10:05 varshith257

@varshith257 ok , right onto it :+1:

karthxk07 avatar May 07 '24 11:05 karthxk07

@palisadoes @varshith257 If these tests share dependencies or resources, running them concurrently could lead to race conditions, flakiness, or incorrect results due to interference.

Instead, it might be more beneficial to focus on optimizing the test execution strategy within a single process or thread, ensuring that tests with dependencies or shared resources are executed sequentially or in a controlled manner to prevent interference.

gautam-divyanshu avatar May 11 '24 11:05 gautam-divyanshu

@palisadoes I think we should focus on fine-tuning pool options. ,  Currently we use     "test": "vitest run --pool forks --poolOptions.forks.singleFork --coverage",,  I tried using other options, but some test cases failed.

gautam-divyanshu avatar May 11 '24 12:05 gautam-divyanshu

image

gautam-divyanshu avatar May 11 '24 12:05 gautam-divyanshu

@palisadoes and resources for this are very limited, nothing clearing explains, it depends on different codebases.

gautam-divyanshu avatar May 11 '24 12:05 gautam-divyanshu

@varshith257 What do you think?

gautam-divyanshu avatar May 12 '24 19:05 gautam-divyanshu

I saw this in a devops newsletter

Large monorepos can often pose a challenge for traditional CI systems, leading to slow build times. This post looks at using Yarn to only run tests against components that have changed, speeding up feedback.

https://mathieularose.com/ci-cd-pipeline-change-based-testing-yarn-based-monorepo

palisadoes avatar May 19 '24 13:05 palisadoes

@palisadoes How can we rectify that disrupts other files that have dependencies if changed files are only tested?

gautam-divyanshu avatar May 19 '24 13:05 gautam-divyanshu

I just saw the link to it and wondered whether it would be useful.

Do you think the selective parallelism method is the best approach for us? If so, then go ahead.

palisadoes avatar May 19 '24 15:05 palisadoes

@palisadoes I am trying to run parallel tests for Mutation and Query because these will not be dependent on each other. I am just figuring out how I can do this with vitest.

gautam-divyanshu avatar May 19 '24 15:05 gautam-divyanshu

@palisadoes I will create PR by end of this week.

gautam-divyanshu avatar May 27 '24 15:05 gautam-divyanshu

@palisadoes  I am trying to implement change-based testing and will run the test for dependent files.

gautam-divyanshu avatar May 31 '24 16:05 gautam-divyanshu

@palisadoes I tried implementing separate workflows for mutation and query but didn't succeed because of libraries, middlewares, and global dependencies.

Then my observation was that most of the time goes into running test cases of mutation; most of the files have more than 15 test cases; some even have 25 test cases, which leads to excessive time. For that, I tried running test cases in parallel using the vitest inbuilt functionality, i.e., running-tests-concurrently but a lot of test cases were failing.

gautam-divyanshu avatar Jun 07 '24 07:06 gautam-divyanshu