Speed up the API Tests workflow without dropping any test

Aperta
#9,967 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, github-actions
Ambito
ci-cd, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 #9967 rather 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:foundation image 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.yml itself, 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 master branch
  • I have confirmed that this is not a duplicate issue by searching issues
Lingua principale
C#
Stelle
22.6k
Fork
5.4k
Merge medio
11h 39m
PR unite (30g)
104

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di QuantConnect/Lean

Tutte le issue di QuantConnect/Lean

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.