Speed up the API Tests workflow without dropping any test
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with .github/workflows/api-tests.yml and identify the API test command and its current checks. Measure individual QuantConnect.Tests.API.* test times in the workflow's quantconnect/lean:foundation image, then rank the slow tests and propose the stages on this issue while beginning the first stage. Done means all existing tests and checks still pass, with repeated local runs and before/after timings documented for each pull request.
Written by the indexing model from the issue text.
Description
Expected Behavior
The API Tests workflow (.github/workflows/api-tests.yml) takes noticeably less time, while running the same tests and checks it runs today.
Actual Behavior
It takes about 16.6 minutes on average, 18.6 at most, over its last 7 successful runs. It builds the solution, then runs the API tests (QuantConnect.Tests.API.*), which call the API.
Potential Solution
Scope:
- In stages, one pull request each. Start by measuring how long each test takes and posting a short plan on this issue: the worst offenders with their times, and the stages, worst offenders first, ordered by time saved for the effort, each a pull request that stands on its own and can be reviewed in one sitting: about 1,000 changed lines and fewer than 40 files at most. Then do the first stage in the same job, without waiting on the plan. Each pull request does one stage, says
Part of #9967rather than closing the issue, and ends with what's left for the next stage. The last stage's pull request closes the issue. When all of it fits within one pull request's limits, one pull request is fine, and it closes the issue. - Keep every test and check it runs today. No skipped, removed, filtered-out or weakened tests or assertions, and no lower coverage. The same tests have to pass, only faster.
- Make the tests themselves faster. Replace fixed sleeps with waiting on the condition they wait for, and share or cut repeated expensive setup.
- Use parallelism where tests are independent.
- Clean up after every test. Tests often leave tasks, threads, timers or engine instances running after they end, which slows down every test after them: stop and dispose of what each test starts.
- Mock where it helps, such as a slow external call or a heavy dependency a test doesn't check, as long as the test still checks what it set out to.
- Keep them consistent. Faster must not mean flaky: no race conditions, no state shared between tests running at once, no crashes or hangs. Run the changed suite several times in a row, in parallel where it runs in parallel, and put the number of runs and their results in the pull request. A test that already fails now and then gets fixed when the cause is in the test itself, such as a race in its setup, a fixed sleep or state shared with another test, not retried or skipped. When the cause is in the code under test, describe it in the pull request instead. CI runs for many pull requests also happen at the same time, against the same API account and the same runners, so a test can't rely on state another run could change: each run creates its own, as the API tests do with a new project every time. Sharing a project between tests or runs to save time would break that, so it's not a speed-up to take.
- Measure locally first, in the workflow's own
quantconnect/lean:foundationimage with its commands, and put the before and after times in the pull request. Push once the change is measured, not to try ideas on CI. - Use only this workflow's runners. On the pull request, cancel the runs of the other workflows, which this change doesn't affect, so the shared self-hosted runners stay free.
- Workflow file changes: if the speed-up needs a change to
.github/workflows/api-tests.ymlitself, describe it in the pull request description.
Calls to the API often wait on server-side work, such as a compile or a backtest finishing: poll the state they wait for, at a short interval, rather than sleeping a fixed time, and run independent fixtures at once.
Checklist
- I have completely filled out this template
- I have confirmed that this issue exists on the current
masterbranch - I have confirmed that this is not a duplicate issue by searching issues
- Dominant language
- C#
- Stars
- 22.6k
- Forks
- 5.4k
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 104
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QuantConnect/Lean
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
QuantConnect/Lean#10216 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10206 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
QuantConnect/Lean#10199 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
QuantConnect/Lean#10198 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10197 ·
Maintainers usually reply within 1 day
All issues in QuantConnect/Lean
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day