Skip to content

fix(testing): prevent DI container disposal during test execution#234

Merged
j-d-ha merged 7 commits into
mainfrom
fix/di-container-disposed-before-being-called
Dec 14, 2025
Merged

fix(testing): prevent DI container disposal during test execution#234
j-d-ha merged 7 commits into
mainfrom
fix/di-container-disposed-before-being-called

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 14, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR fixes an issue where the DI container was being disposed before test invocations could complete, causing test failures. The fix adds proper delay handling in DiLambdaTests.cs to ensure the container remains available throughout the test execution lifecycle.

Additionally includes:

  • XML documentation formatting improvements across Lambda Testing models and extensions
  • Lambda default timeout value adjustments
  • Editor configuration updates for code formatting
  • Removal of unused package references from unit test projects
  • Version bump to 2.0.0-beta.5

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Fixes the DI container disposal timing issue in test execution.


💬 Notes for Reviewers

The primary fix is in DiLambdaTests.cs where delay handling was added to prevent the DI container from being disposed prematurely during test execution. The other changes are maintenance updates including documentation formatting and version bumping.

…ects

- Removed `System.Net.Http` and `System.Text.RegularExpressions` package references from test projects.
- Streamlined dependencies to improve project maintainability.
…ring test execution

- Added delays in `DiLambdaTests` to prevent the DI container from being disposed prematurely.
- Updated `CancellationToken` usage to use `TestContext.Current.CancellationToken`.
- Improved test stability in scenarios where initialization fails or exits early.
… resolver rules

- Updated `.editorconfig` to apply formatting rules to all `HostFactoryResolver.cs` files.
- Adjusted Rider settings to ensure consistent reformatting across multiple languages.
- Enabled C# documentation comments formatting in Rider settings.
- Updated formatting in `LambdaServerOptions` for consistent inline documentation.
- Changed default `FunctionTimeout` from 15 minutes to 3 seconds with relevant documentation link.
- Simplified exception handling logic in `DeferredHostBuilder`.
…ng models and extensions

- Replaced multi-line XML documentation with consistent single-line descriptions for readability.
- Simplified and formatted comments in `InvocationResponse`, `ErrorResponse`, `InitResponse`, and related models.
- Standardized usage of `<see cref>` inline references for improved clarity and consistency in codebase.
- Adjusted extension method comments in `LambdaTestServerExtensions` to align with updated formatting style.
- Changed `FunctionTimeout` default in `LambdaServerOptions` from 3 minutes to 3 seconds.
- Updated inline XML documentation link for better clarification.
- Updated the version in `Directory.Build.props` to 2.0.0-beta.5.
@github-actions github-actions Bot added the type: fix Bug fix label Dec 14, 2025
@j-d-ha j-d-ha changed the title fix(tests): prevent DI container disposal during test execution fix(testing): prevent DI container disposal during test execution Dec 14, 2025
@j-d-ha
j-d-ha enabled auto-merge (squash) December 14, 2025 17:33
@sonarqubecloud

Copy link
Copy Markdown

@j-d-ha
j-d-ha merged commit b85397d into main Dec 14, 2025
6 of 7 checks passed
@j-d-ha
j-d-ha deleted the fix/di-container-disposed-before-being-called branch December 14, 2025 17:34
@codecov

codecov Bot commented Dec 14, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #234      +/-   ##
==========================================
- Coverage   89.61%   87.91%   -1.70%     
==========================================
  Files         104      122      +18     
  Lines        2128     2864     +736     
  Branches      253      334      +81     
==========================================
+ Hits         1907     2518     +611     
- Misses        129      216      +87     
- Partials       92      130      +38     
Files with missing lines Coverage Δ
...ions/Options/DefaultLambdaJsonSerializerOptions.cs 100.00% <ø> (ø)
...OpenTelemetry/MiddlewareOpenTelemetryExtensions.cs 93.75% <ø> (ø)
src/MinimalLambda.Testing/DeferredHostBuilder.cs 86.15% <ø> (ø)
.../MinimalLambda.Testing/LambdaApplicationFactory.cs 68.26% <ø> (ø)
...ng/LambdaApplicationFactoryContentRootAttribute.cs 0.00% <ø> (ø)
src/MinimalLambda.Testing/LambdaHttpHandler.cs 82.75% <ø> (ø)
src/MinimalLambda.Testing/LambdaTestServer.cs 83.52% <ø> (ø)
...inimalLambda.Testing/LambdaTestServerExtensions.cs 100.00% <ø> (ø)
src/MinimalLambda.Testing/Models/ErrorResponse.cs 88.88% <ø> (ø)
src/MinimalLambda.Testing/Models/InitResponse.cs 100.00% <ø> (ø)
... and 8 more

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c0129e...033ca22. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant