Skip to content

Run the API project tests in parallel and fix their failures - #10149

Merged
Martin-Molinero merged 2 commits into
masterfrom
kronos/feature-9967-faster-reliable-api-tests
Nov 16, 2026
Merged

Martin-Molinero merged 2 commits into
masterfrom
kronos/feature-9967-faster-reliable-api-tests

Conversation

@quantconnect-kronos

@quantconnect-kronos quantconnect-kronos Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of #9967 (stage 1 of the plan posted on the issue)

What changed and why

Speed: ProjectTests runs its tests in parallel. Until now they ran one at a time, about 11 of the workflow's 12.3 test minutes. The fixture is now Parallelizable(ParallelScope.All). The tests that change the shared TestProject/TestBacktest are NonParallelizable, so no other test reads them mid-change: CRUD_ProjectFiles_Successfully, RU_ProjectNodes_Successfully, UpdateBacktestName, UpdatesBacktestTags, UpdateProjectNameAndDescription, UpdateBacktestThroughTheInterfaceKeepsTheName. So is ListProjectsPagesTheAccountProjects, which reads the account's project list twice and expects the first project to still be there. Every other test creates and deletes its own project, as before. ObjectStoreTests keeps running its tests in sequence (see below).

Reliability: the fixes from the issue comment, all in the tests.

  • CreatesOptimization (and OptimizationTests) request 6 parallel nodes, the most the api accepts, instead of 12.
  • SetObjectStoreWorksAsExpected/DeleteObjectStoreWorksAsExpected each write under a new key, /CI_TEST_TEMPORARY/<guid>, instead of the fixed /CI_TEST/Ricardo every concurrent run shared. The delete test pauses a second between listing polls; it used to poll with no pause.
  • UpdateProjectNameAndDescription renames to a second new name instead of back to the original, which the api refused with Given name already exist in your organization. It still checks that a name-only update keeps the description.
  • ReadBacktestReportWaitsUntilTheReportIsGenerated and ReadBacktestOrdersReportAndChart read the report until it's generated, up to 5 minutes, instead of failing after the client's 1-minute poll. The assertions are unchanged.
  • The success cases of GetObjectStoreWorksAsExpected ask for the download again when the client's 5-minute wait for its url runs out. A new attempt can start up to 6 minutes into the test, and each call waits up to 5 minutes, so the worst case for one of these cases is about 11 minutes. To keep that from killing the test host, the workflow's per-test --blame-hang-timeout goes from 7 to 12 minutes (the only change to .github/workflows/api-tests.yml). On master the same case fails one assertion at 5 minutes.
  • SetObjectStoreWorksAsExpected/DeleteObjectStoreWorksAsExpected also delete their key in a finally, so a failed run doesn't leave it behind.
  • CreatesLiveAlgorithm and ReadLiveInsightsWorksAsExpected wait up to 5 minutes for a free live node and deploy on it. They retry when another run takes the node first, instead of asserting No free Live Nodes found at once.

Two more causes found while running the suite in parallel, both already present on master:

  • ApiTestBase.ReloadConfiguration resets and refills the shared static configuration. Two fixtures setting up at once can collide, which fails a whole fixture's OneTimeSetUp with Can not add property api-url to Newtonsoft.Json.Linq.JObject. Property with the same name already exists. It now runs under a lock.
  • *_CreatedCompiledAndBacktested_Unsuccessully("OnData") read the backtest status once after the wait. That wait stops as soon as the final statistics are in, and under load the api can report them before the Runtime Error status: the test read Completed. while the api later showed Runtime Error. The test now polls the status until it is the expected one, up to a minute.

The default deadlines of WaitForCompilerResponse and WaitForBacktestCompletion go from 60 s to 300 s. With the tests running together, compiles and backtests can wait in the node queue, and most callers already passed 300 or 600. A deadline only matters when something is wrong: the waits return as soon as their condition holds.

No test, case or assertion is removed, skipped or weakened.

Measurements

API Tests workflow on this pull request's head commit (054d5e0), run by pushing the same commit to a branch name without /, since the workflow only runs on such pushes (run):

Workflow Build Tests Result
master, last fully passing run (2026-10-29) 16.3 min 3.7 min 12.3 min 57 passed
master, recent runs about 15.5 min about 11.7 min fails since 2026-10-29 (CreatesOptimization), plus the flaky tests the issue lists
this change 13.3 min 4.1 min 9.1 min 57 of 57 passed

The test step is now bound by ObjectStoreTests, which still runs its tests one after another: its "The key is not present" case took 5 min 2 s, DeleteObjectStoreWorksAsExpected 1 min, and two download cases about 50 s each, about 8.6 minutes with set-up. In ProjectTests, the longest tests were ReadLiveInsightsWorksAsExpected (4 min 21 s) and CreatesOptimization (3 min 45 s, now that it requests 6 nodes); the rest finished alongside them.

That is one CI run. For consistency, the suite also ran locally, in the workflow's quantconnect/lean:foundation image with its build and test commands:

  • ProjectTests, 4 runs in a row, in parallel as on CI: the 36 tests that could run locally passed in every run, 6.8 to 7.4 min each. The 2 report tests can't run locally, and fail there on master too.
  • ObjectStoreTests without its download cases, 2 runs: 10 of 10 passed each time, about 1.1 min. The download cases ran only on CI, above.
  • The unit test suite with the main workflow's dotnet test filter: 39,684 passed, 0 failed, 100 skipped.

I left the other workflows' runs on this pull request running, since they're its CI evidence, and cancelled the duplicate runs the extra branch push started.

Left for the next stages

  • ObjectStoreTests, about 7 minutes. GetObjectStoreWorksAsExpected("The key is not present") can only return false after the client's 5-minute poll, since the api never fails a download job for a missing key. Shortening that needs a client-side limit on the wait (a public Api change, a person's call) or the server reporting the job as failed. DeleteObjectStoreWorksAsExpected waits about a minute for the listing to drop the deleted file.
  • ReadLiveInsightsWorksAsExpected, 4 min 15 s. Two live deployments each run a fixed 120 s; waiting on what they wait for, such as the deployment's first orders, would cut most of it.
  • The build step, about 3.7 minutes, if it's still a large share: building only the test project and its dependencies would be a workflow file change.

Run the tests of ProjectTests at the same time. The ones that change the
shared test project or backtest, or page the account's project list, stay
non parallelizable. Lock the configuration reload, which two fixtures'
set-ups can run at once.

Fix what made the API Tests workflow fail:
- request 6 parallel optimization nodes, the most the api accepts
- give each object store test a key of its own instead of a fixed one
  shared by every concurrent run, and pause between listing polls
- rename the project to a second new name instead of back to its first
- keep reading the backtest report, and the object store download,
  until a deadline instead of failing after the client's own poll
- wait for a free live node, deploying on it, until a deadline
- poll a finished backtest's status until it is the expected one, since
  the api can report the final statistics first

Part of #9967

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quantconnect-kronos quantconnect-kronos Bot added kronos:develop:working develop: in progress kronos:review Request review labels Nov 16, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 16, 2026

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes.

Description: the Measurements section describes the environment the local runs used. Please edit it to the outcome only (which tests ran, how many runs, what passed and how long they took), not what the environment had or lacked.

1. The object store download retry can outlast the 7-minute hang timeout, and the description says it can't (inline comment). Api.GetObjectStore polls up to 5 minutes for the url on every call (Api/Api.cs:1387). The loop checks its 6-minute deadline only before each call, so a retry that starts at about 5 minutes can run to about 10. --blame-hang-timeout 7minutes is per test, so if the url is still slow, the test host gets killed and the rest of the run is lost. On master the same case fails one assertion at 5 minutes. Since the client's wait can't be shortened without an Api change, the options I see are: raise the hang timeout in api-tests.yml to cover the longest retry (the issue allows a workflow change described in the pull request), or keep the retry only for calls that fail quickly. Either way, the description should give the real worst case.

2. No run of the changed workflow yet. The local runs covered ProjectTests alone, 4 times, with 36 of 38 passing and the 2 report tests explained. Two things haven't run at all: the download cases of GetObjectStoreWorksAsExpected, and the two fixtures together, which is what CI runs and what the expected ~7 minutes is based on. The workflow only runs on push to a branch name without /, so pushing this head commit to a branch named that way runs the real API Tests job before merge. Please add its outcome and time to the description.

What I checked and found sound:

  • Parallelism: NUnit runs NonParallelizable tests in the non-parallel shift, which doesn't overlap the parallel one. I listed every test that touches TestProject/TestBacktest. The ones that change them (files, nodes, backtest name, tags, note, project rename) are all marked. The rest only read, or create and delete their own project. ObjectStoreTests keeps running its tests one after another.
  • The ReloadConfiguration lock, the new keys under their own folder (so the /CI_TEST download cases don't pick them up), the 1 s pause in the delete poll, the status poll for the failing backtest cases, WaitForBacktestReport (ReadBacktestReport sleeps 10 s per request, so the loop doesn't spin), and CreateLiveAlgorithmOnAFreeNode. That helper still checks Success and the error message, and the callers still check the response's JSON.
  • No test, case or assertion was removed. The rename test still checks that a name-only update keeps the description.
  • Other CI checks are green. API Tests was skipped, as explained above.

Minor, not blocking: the per-test object store keys are only deleted when every assertion before the delete passes, so failed runs leave GUID keys under /CI_TEST_TEMPORARY. Deleting them in a finally would keep the folder from growing.

No other repository needs an update.

Label: risk:high. The change only touches tests and is easy to revert, but risk:low still needs a passing run of the API Tests workflow on this commit (item 2) and a fix for item 1.

if (isSuccessExpected)
{
// Under load the download url can take longer than the client polls for it, a new request can get it sooner
while (!result && DateTime.UtcNow < finish)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each GetObjectStore call can take up to 5 minutes (Api.cs:1387), and finish is only checked before a call. A retry that starts at about 5 minutes can therefore end at about 10, past the per-test --blame-hang-timeout 7minutes, which kills the test host and loses the rest of the run, where master fails a single assertion at 5 minutes. Either raise the hang timeout in the workflow to cover the longest retry, or retry only after a call that failed quickly, and give the real worst case in the description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 054d5e0: the workflow's per-test --blame-hang-timeout goes from 7 to 12 minutes. A new attempt starts only before the 6-minute mark and each call waits up to 5 minutes, so the worst case for one of these cases is about 11. I kept the retry rather than limiting it to quick failures, because a slow url is the case the retry is for. The comment by the loop and the description now give that worst case.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:high High risk and removed kronos:review:working review: in progress labels Nov 16, 2026
A retry of the download can start up to 6 minutes into the test and wait
5 more for its url, so raise the workflow's per-test hang timeout from 7
to 12 minutes instead of letting it kill the test host. Delete the object
store test keys in a finally, so a failed run doesn't leave them behind.

Part of #9967

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quantconnect-kronos

Copy link
Copy Markdown
Contributor Author

Addressed the review in 054d5e0:

  1. Retry versus hang timeout. .github/workflows/api-tests.yml raises --blame-hang-timeout from 7 to 12 minutes, covering the about 11-minute worst case of a download case that retries. The description and the comment by the loop give that worst case. It's the only workflow change.
  2. A run of the changed workflow. I pushed this head commit to a branch named without /. API Tests passed 57 of 57: workflow 13.3 min (16.3 on the last passing master run), tests 9.1 min (12.3). The download cases and both fixtures ran together. The test step is now bound by ObjectStoreTests, about 8.6 min, mostly the 5-minute missing-key case: that's stage 2. I cancelled the duplicate runs of the other workflows that push started and deleted the branch.
  3. Description. The Measurements section now gives the outcome only: what ran, how many runs, what passed and how long it took.
  4. Minor. The two object store key tests delete their key in a finally.

@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 16, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 16, 2026
@quantconnect-kronos-reviewer
quantconnect-kronos-reviewer Bot marked this pull request as ready for review November 16, 2026 16:53

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Both findings from my last review are resolved:

  1. Download retry versus hang timeout. --blame-hang-timeout goes from 7 to 12 minutes, the only workflow change. That covers the worst case: a new attempt starts before the 6-minute mark and GetObjectStore waits up to 5 minutes for its url, about 11 minutes in total. The comment by the loop and the description now give that figure.
  2. A run of the changed workflow. The API Tests run on this head commit passed 57 of 57 (I checked the log): ProjectTests in parallel with ObjectStoreTests, the download cases included. The tests took 9.1 min, down from 12.3. The description gives the outcome only.

The minor point is done too. Both object store key tests delete their key in a finally. On success, that second delete hits a key that's already gone. DeleteObjectStore returns an unsuccessful response there instead of throwing (Api/Api.cs:1479), so it can't fail the test.

CI: every check on the pull request branch passes. The six fail entries are the duplicate runs the extra branch push started, on the same commit. They were cancelled, not failed.

No other repository needs an update.

Label: risk:low. The change touches only tests and the API Tests workflow's timeout, so it's easy to revert. It has no effect on Lean itself, and a passing run of the changed workflow on this commit backs it.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:low Low risk and removed risk:high High risk kronos:review:working review: in progress labels Nov 16, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 16, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 16, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 16, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this head commit. No blocking findings after reviewing the complete change and the earlier discussion.

The earlier requests are resolved: the workflow's hang timeout is now 12 minutes, the download retry's timing is documented, both temporary-key tests clean up in a finally, and the description includes a passing run of the changed workflow.

Verification:

  • Checked the API Tests run: it ran this exact commit and passed all 57 tests, including both fixtures and the download cases. Test execution took about 9.1 minutes.
  • Rebuilt the test project in Release successfully. Focused end-to-end execution of SetObjectStoreWorksAsExpected and DeleteObjectStoreWorksAsExpected passed. This was not a second full-suite run.
  • Checked the parallel-test isolation and retry paths. The shared-project/backtest mutations remain non-parallelizable. Concurrent same-name project creation also succeeded with distinct project IDs.
  • The six checks displayed as failures are cancelled duplicate runs, not test failures; the corresponding PR-branch checks passed.

No other repository needs an update.

Label: risk:low. This is a small, reversible change confined to tests and the API Tests workflow's timeout, with no production API or engine behavior change and a passing full workflow on the reviewed commit.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 16, 2026
@quantconnect-kronos quantconnect-kronos Bot added kronos:develop:idle develop: paused and removed kronos:develop:working develop: in progress labels Nov 16, 2026
@Martin-Molinero
Martin-Molinero merged commit 2c9491a into master Nov 16, 2026
9 of 15 checks passed
@Martin-Molinero
Martin-Molinero deleted the kronos/feature-9967-faster-reliable-api-tests branch November 16, 2026 18:15
@quantconnect-kronos quantconnect-kronos Bot removed the kronos:develop:idle develop: paused label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Low risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant