CI/tests: investigate and resolve timeout issues [Windows primarily]
https://github.com/ankidroid/Anki-Android/actions/runs/38760697234/job/116510932966
Looks like a genuine timeout.
Either:
- Improve our test execution speed
- Increase the timeout
I'd rather put a bit of effort into (1). We've also got a couple of backend updates pending which should significantly improve test speed
- https://github.com/ankidroid/Anki-Android-Backend/issues/674
- https://github.com/ankidroid/Anki-Android-Backend/pull/713
Hi David, Iam looking to make my first contribution to AnkiDroid and noticed the Windows test timeout issue. I saw that improving test execution speed is preferred over simply increasing the timeout. Are there any small, independently actionable test-performance improvements that would be suitable for a first-time contributor? I'd be happy to investigate an existing test bottleneck and contribute a focused fix with measurements.
Hi @RohanBenielE This /probably/ isn't a good first issue.
But:
My belief is that we can get a large speedup by optimizing our code coverage reporting: JaCoCo. I believe we've collecting coverage from classes which are not sent to codecov, and this will produce a significant saving.
I won't have time to fully define this, I suspect another 'Good First Issue' would be better, but if you feel there's enough to look into, this would be greatly appreciated. It's not an area of the code which I know well, so sadly I can't provide more guidance.
- I started this on https://github.com/ankidroid/Anki-Android/pull/22548
Hi @david-allison I've started investigating the Windows unit-test timeout. The latest run shows :AnkiDroid:testPlayDebugUnitTest taking around 29 minutes, with the overall job hitting the 45-minute limit.
I inspected ankidroid.plugins.jacoco.gradle.kts and found that JaCoCo is configured on test tasks, while the report task also filters classes. Before making changes, has anyone measured the overhead from JaCoCo instrumentation or identified specific classes that are unnecessarily included in coverage? I'd like to benchmark the current behavior and focus on a measurable improvement.
We haven't benchmarked, that would be the first step.
I know Jacoco adds significant overhead, and I believe it's running on classes which we don't report on.
If this hypothesis is correct, fixing the issue would greatly improve our test execution time
In addition, today I'll be merging a backend fix which will allow for faster execution of tests, but it's a fairly complex process to merge into Anki-Android, I suspect this is a few weeks off
Hi @david-allison , I tested the full unit-test suite on Windows with JaCoCo enabled and disabled to check whether JaCoCo was making the tests slower.
JaCoCo enabled: 47m 02s — build successful. JaCoCo disabled: 47m 47s — build successful.
Both runs reported 3,788 tests, 0 failures, 0 errors, and 105 skipped tests. I used --no-daemon --max-workers=1 for both runs.
Disabling JaCoCo did not make the tests faster. In fact, the run without it took around 45 seconds longer. However, I ran each configuration only once, so this small difference might just be normal variation between runs. From these results, I couldn't confirm that JaCoCo is a major reason the Windows tests are taking so long. I haven't made any code or configuration changes. Would you suggest that I run the tests again with JaCoCo enabled and disabled to check the results, or should I look into other possible reasons why the Windows tests are taking so long?
I'm surprised, I expect JaCoCo to be significant, intuition says about 10% of the build time, but I'm fine to be mistaken
EDIT: Please check again
Thanks, @david-allison I will recheck this with a more controlled comparison, ensuring the test tasks and conditions are equivalent. I'll measure the test execution and JaCoCo report overhead separately before drawing a conclusion.
@RohanBenielE how're things looking here?
Hi @david-allison thanks for checking in. I haven't completed the follow-up investigation yet. My initial comparison didn't show a speedup from disabling JaCoCo, so I want to revisit this with a more controlled approach before drawing any conclusions. Over the next few days, I'll focus on making the comparison reproducible and separating test execution time from coverage/reporting overhead, so we can identify where the time is actually being spent. I'll share the measurements and next steps once I have a clearer result, rather than making changes based on assumptions.
Note: some JaCoCo filtering is performed in:
- https://github.com/david-allison/Anki-Android/commit/7583da050b
- https://github.com/david-allison/Anki-Android/commit/2831ce4a0a
- https://github.com/david-allison/Anki-Android/commit/69d6267981
These are AI slop currently, but feel free to cherry-pick and fix these up, these were implemented in a general performance pass, and there's likely a lot to go through in general with JaCoCo, especially after a thorough inveestigation.
These commits will take a long while to make it into main
Thanks @david-allison I'll go through all three commits individually and understand the existing JaCoCo filtering approach before cherry-picking anything.
I've already started investigating the Windows test timeout. I ran the full unit test suite with JaCoCo enabled and disabled. Both runs completed successfully with 3,788 tests (0 failures, 0 errors, 105 skipped). The runtimes were approximately 47m 02s with JaCoCo enabled and 47m 47s with it disabled, so the initial comparison didn't show the expected improvement.
I also looked into the individual test task, which takes around 27 minutes, and I'm continuing to investigate where the remaining build time is being spent. My next step is to examine the filtering changes in your commits, understand their impact on instrumentation and coverage, and benchmark any improvements with controlled, repeatable runs.
I'll share the findings before making broader changes👍