Repository navigation
docs: explain when ClassDataSource instances are created - #7046
Conversation
Constructors run while tests are built, before scheduling, so [NotInParallel] cannot order them. Recommend IAsyncInitializer for work that touches shared state. Refs #7044
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
ReviewDocs-only change, and a useful one: it explains the build-time vs. execution-time distinction behind discussion #7044. The Notes (non-blocking):
Looks good to merge. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b00ae59acc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| TUnit constructs `ClassDataSource<T>` instances while it builds tests, before any test runs. This happens for every `SharedType`. Attributes that affect scheduling, such as `[NotInParallel]`, do not change it. With `SharedType.None`, the constructor can also run more than once for each data row. | ||
|
|
||
| `IAsyncInitializer.InitializeAsync` runs later, during execution. It runs right before the first test that receives the instance, after the `[Before(Class)]` hooks, and within that test's `[NotInParallel]` constraint. |
There was a problem hiding this comment.
Qualify timing guarantees for static-property injection
When [ClassDataSource<T>] decorates a supported static property, as in tests/TUnit.UnitTests/StaticPropertyDataSourceTests.cs:15-17, the scheduler initializes static properties before grouping parallel constraints (src/TUnit.Engine/Scheduling/TestScheduler.cs:110-117), and that path creates the value and invokes ObjectInitializer.InitializeAsync (src/TUnit.Engine/Services/StaticPropertyHandler.cs:54-73). Consequently, its constructor does not run during ordinary test building and its initializer is neither after [Before(Class)] nor within [NotInParallel]; qualify these guarantees as applying to test/class parameter and instance-property injection, or document static properties separately.
Useful? React with 👍 / 👎.
|
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.74.0 to 1.75.0. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.75.0 <!-- Release notes generated using configuration in .github/release.yml at v1.75.0 --> ## What's Changed ### Other Changes * docs: explain when ClassDataSource instances are created by @thomhurst in thomhurst/TUnit#7046 * feat(aspnetcore): add PerTestWebApplicationTest with per-test CreateFactoryAsync by @thomhurst in thomhurst/TUnit#7047 * fix(aspnetcore): make WebApplicationTest.HttpCapture return the registered capture by @thomhurst in thomhurst/TUnit#7048 ### Dependencies * chore(deps): update tunit to 1.74.0 by @thomhurst in thomhurst/TUnit#7032 * chore(deps): update dependency imposter to 0.2.19 by @thomhurst in thomhurst/TUnit#7034 * chore(deps): update dependency polyfill to 11.4.4 by @thomhurst in thomhurst/TUnit#7033 * chore(deps): update dependency dompurify to v3.4.17 by @thomhurst in thomhurst/TUnit#7037 * chore(deps): update dependency imposter to 0.2.21 by @thomhurst in thomhurst/TUnit#7036 * chore(deps): update dependency imposter to 0.2.23 by @thomhurst in thomhurst/TUnit#7038 * chore(deps): update dependency awssdk.sqs to 4.0.100.17 by @thomhurst in thomhurst/TUnit#7039 * chore(deps): update dependency messagepack to 3.1.12 by @thomhurst in thomhurst/TUnit#7040 * chore(deps): update dependency polyfill to 11.4.5 by @thomhurst in thomhurst/TUnit#7042 * chore(deps): update dependency imposter to 0.2.24 by @thomhurst in thomhurst/TUnit#7043 **Full Changelog**: thomhurst/TUnit@v1.74.0...v1.75.0 Commits viewable in [compare view](thomhurst/TUnit@v1.74.0...v1.75.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [TUnit.Core](https://github.com/thomhurst/TUnit) from 1.72.16 to 1.75.0. <details> <summary>Release notes</summary> _Sourced from [TUnit.Core's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.75.0 <!-- Release notes generated using configuration in .github/release.yml at v1.75.0 --> ## What's Changed ### Other Changes * docs: explain when ClassDataSource instances are created by @thomhurst in thomhurst/TUnit#7046 * feat(aspnetcore): add PerTestWebApplicationTest with per-test CreateFactoryAsync by @thomhurst in thomhurst/TUnit#7047 * fix(aspnetcore): make WebApplicationTest.HttpCapture return the registered capture by @thomhurst in thomhurst/TUnit#7048 ### Dependencies * chore(deps): update tunit to 1.74.0 by @thomhurst in thomhurst/TUnit#7032 * chore(deps): update dependency imposter to 0.2.19 by @thomhurst in thomhurst/TUnit#7034 * chore(deps): update dependency polyfill to 11.4.4 by @thomhurst in thomhurst/TUnit#7033 * chore(deps): update dependency dompurify to v3.4.17 by @thomhurst in thomhurst/TUnit#7037 * chore(deps): update dependency imposter to 0.2.21 by @thomhurst in thomhurst/TUnit#7036 * chore(deps): update dependency imposter to 0.2.23 by @thomhurst in thomhurst/TUnit#7038 * chore(deps): update dependency awssdk.sqs to 4.0.100.17 by @thomhurst in thomhurst/TUnit#7039 * chore(deps): update dependency messagepack to 3.1.12 by @thomhurst in thomhurst/TUnit#7040 * chore(deps): update dependency polyfill to 11.4.5 by @thomhurst in thomhurst/TUnit#7042 * chore(deps): update dependency imposter to 0.2.24 by @thomhurst in thomhurst/TUnit#7043 **Full Changelog**: thomhurst/TUnit@v1.74.0...v1.75.0 ## 1.74.0 <!-- Release notes generated using configuration in .github/release.yml at v1.74.0 --> ## What's Changed ### Other Changes * fix(mocks): eliminate trim/AOT warnings on Native AOT publish by @thomhurst in thomhurst/TUnit#7029 * feat(engine): raise thread pool minimum when blocking tests starve the pool by @thomhurst in thomhurst/TUnit#7030 * feat(mocks): add ClearCalls, PassThrough toggle and string/type/reference matchers by @Quattordici in thomhurst/TUnit#7018 ### Dependencies * chore(deps): update tunit to 1.73.19 by @thomhurst in thomhurst/TUnit#7008 * chore(deps): update dependency imposter to 0.2.5 by @thomhurst in thomhurst/TUnit#7010 * chore(deps): update dependency mockolate to 3.6.0 by @thomhurst in thomhurst/TUnit#7011 * chore(deps): update dependency imposter to 0.2.6 by @thomhurst in thomhurst/TUnit#7012 * chore(deps): update dependency stackexchange.redis to 3.4.0 by @thomhurst in thomhurst/TUnit#7013 * chore(deps): update xunit by @thomhurst in thomhurst/TUnit#7014 * chore(deps): update dependency imposter to 0.2.7 by @thomhurst in thomhurst/TUnit#7016 * chore(deps): update dependency nunit3testadapter to 6.3.1 by @thomhurst in thomhurst/TUnit#7015 * chore(deps): update verify to 33.3.3 by @thomhurst in thomhurst/TUnit#7019 * chore(deps): update dependency imposter to 0.2.8 by @thomhurst in thomhurst/TUnit#7020 * chore(deps): update dependency imposter to 0.2.10 by @thomhurst in thomhurst/TUnit#7021 * chore(deps): update dependency fluentvalidation.dependencyinjectionextensions to 12.2.0 by @thomhurst in thomhurst/TUnit#7022 * chore(deps): update dependency imposter to 0.2.11 by @thomhurst in thomhurst/TUnit#7023 * chore(deps): update dependency imposter to 0.2.12 by @thomhurst in thomhurst/TUnit#7024 * chore(deps): update dependency imposter to 0.2.14 by @thomhurst in thomhurst/TUnit#7025 * chore(deps): update dependency imposter to 0.2.17 by @thomhurst in thomhurst/TUnit#7031 **Full Changelog**: thomhurst/TUnit@v1.73.19...v1.74.0 ## 1.73.19 <!-- Release notes generated using configuration in .github/release.yml at v1.73.19 --> ## What's Changed ### Other Changes * fix(fscheck): apply Verbose, QuietOnSuccess and Parallelism; validate Replay by @JesseKlaasse in thomhurst/TUnit#7001 ### Dependencies * chore(deps): update microsoft.testing to 2.5.1 by @thomhurst in thomhurst/TUnit#6990 * chore(deps): update dependency dotnet-trace to v10.0.750501 by @thomhurst in thomhurst/TUnit#6995 * chore(deps): update tunit to 1.73.5 by @thomhurst in thomhurst/TUnit#6996 * chore(deps): update verify to 33.3.2 by @thomhurst in thomhurst/TUnit#6997 * chore(deps): update actions/setup-node action to v7.1.0 by @thomhurst in thomhurst/TUnit#6999 * chore(deps): update dependency imposter to 0.2.3 by @thomhurst in thomhurst/TUnit#7000 * chore(deps): update dependency testcontainers.kafka to 4.16.0 by @thomhurst in thomhurst/TUnit#7002 * chore(deps): update dependency imposter to 0.2.4 by @thomhurst in thomhurst/TUnit#7004 * chore(deps): update dependency testcontainers.postgresql to 4.16.0 by @thomhurst in thomhurst/TUnit#7003 * chore(deps): update dependency awssdk.sqs to 4.0.100.16 by @thomhurst in thomhurst/TUnit#7007 * chore(deps): update dependency testcontainers.redis to 4.16.0 by @thomhurst in thomhurst/TUnit#7005 ## New Contributors * @JesseKlaasse made their first contribution in thomhurst/TUnit#7001 **Full Changelog**: thomhurst/TUnit@v1.73.5...v1.73.19 ## 1.73.5 <!-- Release notes generated using configuration in .github/release.yml at v1.73.5 --> ## What's Changed ### Other Changes * fix: Ignore default start timestamps in HTML report by @SnakyBeaky in thomhurst/TUnit#6942 * fix(playwright): send trace context headers only to origins under test by @thomhurst in thomhurst/TUnit#6993 ### Dependencies * chore(deps): update dependency imposter to 0.2.2 by @thomhurst in thomhurst/TUnit#6988 * chore(deps): update tunit to 1.73.0 by @thomhurst in thomhurst/TUnit#6989 * chore(deps): update mstest to 4.5.1 by @thomhurst in thomhurst/TUnit#6991 **Full Changelog**: thomhurst/TUnit@v1.73.0...v1.73.5 ## 1.73.0 <!-- Release notes generated using configuration in .github/release.yml at v1.73.0 --> ## What's Changed ### Other Changes * fix(aspnetcore): initialize web application factories through services by @thomhurst in thomhurst/TUnit#6956 * docs: give the site a green-bar identity by @thomhurst in thomhurst/TUnit#6959 * docs: make examples work on Linux and macOS by @Quattordici in thomhurst/TUnit#6964 * fix(runtime): correct Windows-shaped assumptions on Linux and macOS by @Quattordici in thomhurst/TUnit#6962 * build: make the repo build, test and script cleanly on macOS and Linux by @Quattordici in thomhurst/TUnit#6963 * fix(globalization): culture-invariant generators, analyzers and code fixers; enforce it by @Quattordici in thomhurst/TUnit#6969 * chore: update NuGet dependencies and split versions per target framework by @Quattordici in thomhurst/TUnit#6972 * feat: add [PairwiseDataSource] for all-pairs test case generation by @AArnott in thomhurst/TUnit#6971 ### Dependencies * chore(deps): update tunit to 1.72.16 by @thomhurst in thomhurst/TUnit#6953 * chore(deps): update dependency masstransit to 9.2.3 by @thomhurst in thomhurst/TUnit#6954 * chore(deps): update dependency messagepack to 3.1.11 by @thomhurst in thomhurst/TUnit#6958 * chore(deps): update dependency polyfill to 11.4.2 by @thomhurst in thomhurst/TUnit#6965 * chore(deps): update verify to 33.3.0 by @thomhurst in thomhurst/TUnit#6966 * chore(deps): update dependency polyfill to 11.4.3 by @thomhurst in thomhurst/TUnit#6968 * chore(deps): update microsoft.testing to 2.5.0 by @thomhurst in thomhurst/TUnit#6978 * chore(deps): bump compression from 1.8.1 to 1.8.2 in /docs by @dependabot[bot] in thomhurst/TUnit#6977 * chore(deps): bump proxy-addr from 2.0.7 to 2.0.8 in /docs by @dependabot[bot] in thomhurst/TUnit#6976 * chore(deps): bump joi from 17.13.7 to 17.13.8 in /docs by @dependabot[bot] in thomhurst/TUnit#6975 * chore(deps): bump source-map-js from 1.2.1 to 1.2.2 in /docs by @dependabot[bot] in thomhurst/TUnit#6974 * chore(deps): bump shell-quote from 1.10.0 to 1.12.0 in /docs by @dependabot[bot] in thomhurst/TUnit#6980 * chore(deps): update dependency microsoft.testing.extensions.codecoverage to 18.12.0 by @thomhurst in thomhurst/TUnit#6979 * chore(deps): update dependency azure.storage.blobs to 12.30.1 by @thomhurst in thomhurst/TUnit#6981 * chore(deps): update dependency imposter to 0.2.0 by @thomhurst in thomhurst/TUnit#6982 * chore(deps): update verify to 33.3.1 by @thomhurst in thomhurst/TUnit#6983 * chore(deps): update aspire to 13.6.1 by @thomhurst in thomhurst/TUnit#6985 * chore(deps): update actions/upload-artifact action to v7.0.2 by @thomhurst in thomhurst/TUnit#6986 * chore(deps): update dependency imposter to 0.2.1 by @thomhurst in thomhurst/TUnit#6987 ## New Contributors * @Quattordici made their first contribution in thomhurst/TUnit#6964 **Full Changelog**: thomhurst/TUnit@v1.72.16...v1.73.0 Commits viewable in [compare view](thomhurst/TUnit@v1.72.16...v1.75.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Context: discussion #7044. A user's
ClassDataSource<T>constructor wrote to a cache, and a[NotInParallel]test that cleared the cache ran before the test that used the instance.[NotInParallel]did not help because constructors run while tests are built, before scheduling starts.This PR adds a "When Instances Are Created" section to
class-data-source.md. It covers:SharedType. WithSharedType.Nonethe constructor can run more than once per row.IAsyncInitializer.InitializeAsyncruns at execution time, within the test's[NotInParallel]constraint.InitializeAsyncover the constructor for side effects on shared state, with an example, and warns not to useIAsyncDiscoveryInitializerfor this.Verification: I compiled the snippet locally with warnings as errors and ran it 3 times, passing every time. Moving the registration into the constructor makes
Product_Is_Cachedfail every time, which reproduces the report.Summary by CodeRabbit
ClassDataSourceinstances are created for each sharing mode.InitializeAsyncruns relative to class hooks and tests, and recommended it for shared-state setup side effects.IAsyncInitializerfromIAsyncDiscoveryInitializerfor initialization during test execution.