Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose method is not called on objects registered for the TestThread container #123

Closed
gasparnagy opened this issue May 10, 2024 · 2 comments · Fixed by #135
Closed

Dispose method is not called on objects registered for the TestThread container #123

gasparnagy opened this issue May 10, 2024 · 2 comments · Fixed by #135
Assignees
Labels
bug Something isn't working

Comments

@gasparnagy
Copy link
Contributor

gasparnagy commented May 10, 2024

Reqnroll Version

1.0.1

Which test runner are you using?

MSTest

Test Runner Version Number

n/a

.NET Implementation

.NET 8.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

No response

Issue Description

If an type is registered to the test thread container (via TestThreadContext.TestThreadContainer), that implements IDisposable, and the container creates an instance (someone resolves it) it is expected that the Dispose method will be called latest before the test execution is finished.

But this will not happen, because Reqnroll does not dispose the test runners at the test-run end (TestRunnerManager.FireTestRunEndAsync).

Steps to Reproduce

See repo/workaround at https://github.com/reqnroll/Sample-ReqOverflow/blob/main/ReqOverflow.Specs.WebUI/Support/BrowserFactory.cs#L61

Link to Repro Project

https://github.com/reqnroll/Sample-ReqOverflow/blob/main/ReqOverflow.Specs.WebUI

@gasparnagy gasparnagy added the bug Something isn't working label May 10, 2024
@gasparnagy gasparnagy self-assigned this May 10, 2024
@Code-Grump
Copy link

Is it expected? The behaviour with IDisposable has always been a bit fuzzy, but the rules I understand is that if you create the object, you are responsible for its lifecycle and calling Dispose() when done. If the container creates the object, it should be responsible for its lifecycle. If the container was given an instance of the object, it should not dispose the object unless it was given an explicit instruction to take ownership of the lifecycle.

@gasparnagy
Copy link
Contributor Author

@Code-Grump Yes, thx for the clarification. I was not clear enough. The problem is that if the container creates the object (so you just have a type registration) the Dispose will not be called. I'll change the description to make this clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants