Speed up the API Tests workflow without dropping any test

オープン
#9,967 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp, github-actions
領域
ci-cd, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
C#
スター
22.6k
フォーク
5.4k
平均マージ
11時間 39分
マージ済み PR(30日)
104

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

QuantConnect/Lean のほかの issue

QuantConnect/Lean の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。