nunit-console
nunit-console copied to clipboard
Assembly loading deduplication
We have test solution containing of few test assemblies, lets say TestA, TestB. They're referencing some Common. While running those tests like nunit-console.exe TestA.dll TestB.dll - Common is being loaded twice, leading to runtime failures.
Can we add a check to the CustomAssemblyLoadContext?
something like this:
protected override Assembly Load(AssemblyName name)
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var loaded = assemblies.FirstOrDefault(x => x.GetName().Name == name.Name);
if (loaded != null)
{
return loaded;
}
var assemblyPath = _resolver.ResolveAssemblyToPath(name);
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
}
since we have no multiple AppDomains in netcore and up - maybe there is no point loading those assemblies multiple times? Of course theres a workaround to simply run them separately, but still would be nice to fix if thats an issue.
@tshcherban
Are you running the NUnit ConsoleRunner or the .NET Core ConsoleRunner?
Unfortunately, we call them both nunit3-console.exe but they come in different packages.
Im running the one from this repository (compiles to nunit-console.exe/dll)
I'm afraid that's the point: there are two different runners in this repo, with different capabilities and the same executable name. Probably a bad decision, but we're stuck with it for now, at least till we do a breaking release. :-(
Since it builds both the exe and the dll, I'm guessing that you're running the .NET Core Console Runner out of the net-6.0 directory. Please take a minute and read #1101 and we'll go on from there. :-)
As you see, there is a lot of uncertainty around the future of that runner. It may end up getting all the features of the standard (net20) console runner or it may be renamed and serve only for use under the .NET CLI. If you're a regular user of the CLI, please add any comments, wishes, etc. to that issue!
If you run your tests using the same command-line, but using the standard runner in the net20 directory, each of your test assemblies will be isolated in separate processes, running under .NET 6.0.
I think your suggested fix is a good one if we continue to allow running multiple assemblies under the .NET Core runner. OTOH if we aren't supporting it, the best fix is probably to give you an error when you enter multiple assemblies on the command line. I think we should probably do whatever dotnet test does in the same situation.
I'd welcome your ideas on which way to go. Even though I'm maintaining it, I'm not a big user of the .NET Core runner myself. And, of course, contributions are always welcome!
Yep, i was running from net-6.0 dir, sorry for missing details. And net20 isnt suitable for me because our tests are in net6 assemblies, net20 runnner is built against net3.5 just cant find needed libraries from net6.
Anyway, i've reproduced a bug with multiple assemblies loading even within one test dll. Ill try to throw redundant stuff out to come with a minimum PoC showing the problem, so it can be debugged more easily. If i manage to do this - ill write a result, summary, proposals to #1101 in one message and will continue there (just to not spam it with intermediate messages).
P.S. correct me if im wrong. If all runners (in-process vs external process) use the same nunit.engine.core - the issue will remain the same for all of them.
This issue has been resolved in version 3.16.0
The release is available on: GitHub. NuGet packages are also available NuGet.org and Chocolatey Packages may be found at Chocolatey.org