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

Run .NET Core Tests from NUnit3 Console #937

Merged
merged 25 commits into from
May 9, 2021
Merged

Run .NET Core Tests from NUnit3 Console #937

merged 25 commits into from
May 9, 2021

Conversation

CharliePoole
Copy link
Collaborator

Another step toward issue #923.

This PR adds TCP as a transport and uses it to run tests under .NET Core.

A .NET Core 3.1 agent has been added. We'll have to decide whether we want others as separate agents. A single package test has been added to exercise the agent. It is run for the NuGet, Chocolatey and Zip packages of the console runner.

The MSI package does not yet include the .NET Core agent. I made a start on this but backed out the changes when I saw that we need to make some decisions about the msi package. I think this will be easier to do if there's a separate PR for it. This one is pretty big as it is.

@CharliePoole
Copy link
Collaborator Author

Unable to figure out why the Azure builds are failing.

Windows job can't find src\NUnitEngine\nunit-agent\obj\Release\x86\netcoreapp3.1\apphost.exe, which is present when I do a local build.

Linux and MacOs jobs say that the net-4.0 framework isn't available.

Not being an Azure guy, I don't even know where to look.

@CharliePoole CharliePoole changed the title Issue 923b Run .NET Core Tests from NUnit3 Console Apr 13, 2021
@ChrisMaddock
Copy link
Member

Not sure if the CI has been re-run since your comment Charlie, but looks like the Windows build is ok. Looks to me like the Mono tests are all failing to start up an agent on Linux/OSX. Not sure what's in this PR that would affect that, however...

@CharliePoole
Copy link
Collaborator Author

@ChrisMaddock @jnm2

The error in building windows continues to appear intermitently, i.e. failure to locate apphost.exe, which should be generated by the restore. I have noticed that when it does appear, there is nothing in the log about restoring nunit-agent.csproj. OTOH nunit-agent-x86.csproj is restored correctly.

I'm working on the hypothesis that nuget is choking on the odd setup we have for the two agent projects: two projects in one directory with separate intermediate output folders, obj and obj\x86. We always knew this was odd and it was somewhat surprising that it actually worked. But I suspect it isn't working for .NET Core builds.

I'll run an experiment, separating the two projects into two different folders and replicating the code.

@CharliePoole
Copy link
Collaborator Author

That worked! The latest commit builds under Windows on both AppVeyor and Azure. The Linux and MacOs builds are still failing on Azure, but not from the same cause.

@CharliePoole CharliePoole force-pushed the issue-923b branch 3 times, most recently from 0c8666d to d5d706e Compare April 15, 2021 21:46
@CharliePoole
Copy link
Collaborator Author

The result is that AppVeyor doesn't seem to have the X86 version of dotnet.exe installed. We could probably install it in our script, but I'd rather save that for later. Instead I make a check for it's availability before trying to run the test, which is more robust.

After this last commit, the only remaining issue is the msi build.

@CharliePoole
Copy link
Collaborator Author

@ChrisMaddock OK, last bit is done and this is ready for final review.

Copy link
Member

@ChrisMaddock ChrisMaddock left a comment

Choose a reason for hiding this comment

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

Great to see this all coming together Charlie! Just a few niggles at this point. 🙂

Just checkpointing the review here as GitHub's gone a bit funny - still a bit more to go through...

<appSettings>
<add key="test.setting" value="54321"/>
</appSettings>
</configuration>
Copy link
Member

Choose a reason for hiding this comment

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

This file is included within the "add agent to msi" commit - is it included accidentally? I'm not sure what the purpose of this is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to add it to make all tests pass. There's a test that reads it. In fact, this should eventually be cleaned up and we should stop using .config files entirely for .NET Core as a part of reworking RuntimeFramework. .runtimeconfig.json is where this should end up.

Hard to figure out the boundaries of a PR... i.e. where do you stop and create a new issue. Personally, I'd prefer not to deal with this one while we still allow --inprocess because that makes RuntimeFramework more complicated. I do think that RuntimeFramework is a good place for me to exercise my preference for tiny PRs. 😃

ProcessorArchitecture="msil"
Source="$(var.InstallImage)bin/agents/netcoreapp3.1/nunit-agent.dll" />
<File Id="nunit_agent.runtimeconfig.json"
Source="$(var.InstallImage)bin/agents/netcoreapp3.1/nunit-agent.runtimeconfig.json" />
Copy link
Member

Choose a reason for hiding this comment

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

I'm not totally clear on what is and isn't required for .NET Core, but I think this should also include nunit-agent.deps.json.

I was also wondering about nunit-agent.dll.config, but I think is actually netfx specific, so it should probably be removed entirely from the netcoreapp agent? I'm not sure how to do that off the top of my head, will give it a go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe that nunit-agent.deps.json is only for use in building the project. It causes nunit-agent.runtimeconfig.json to be generated. If that's wrong, I can add it. Do you have different info? At this point all the tests pass using all the packages.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, ok. I always thought it should be as it details where to load dependencies from at runtime. I'm struggling to find any formal documentation however, or any clear answer elsewhere.

This page seems to be the closest there is. From my reading of that, for a framework-dependent deployment as ours is, the file should be included. What do you think?

https://github.com/dotnet/cli/blob/master/Documentation/specs/runtime-configuration-file.md

Comment on lines 116 to 118
<Component Id="NUNIT_AGENT_ADDINS_NETCORE31" Location="local" Guid="21D2D9FB-A57D-4B02-92A0-6697674FB869">
<File Id="nunit.agent.netcore31.addins" Source="$(var.InstallImage)nunit.agent.addins" />
</Component>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Component Id="NUNIT_AGENT_ADDINS_NETCORE31" Location="local" Guid="21D2D9FB-A57D-4B02-92A0-6697674FB869">
<File Id="nunit.agent.netcore31.addins" Source="$(var.InstallImage)nunit.agent.addins" />
</Component>

I think this addins file points to a dir of netfx extensions, none of which can be loaded by the netcoreapp31 agent. Shall we just leave this out for now? We might want to package netcoreapp-compatible extensions with the engine in future, but they'll probably need to be in a different subdir anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I'll take a look. In fact, this directory should only used for the .NET Core 3.1 agent, so I may be able to just change the content of either the addins file or the directory itself.


<file src="bin/agents/netcoreapp3.1/nunit-agent.dll" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="bin/agents/netcoreapp3.1/nunit-agent.dll.config" target="contentFiles/any/agents/netcoreapp3.1" />
<file src="bin/agents/netcoreapp3.1/nunit-agent.runtimeconfig.json" target="tools/agents/netcoreapp3.1" />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<file src="bin/agents/netcoreapp3.1/nunit-agent.runtimeconfig.json" target="tools/agents/netcoreapp3.1" />
<file src="bin/agents/netcoreapp3.1/nunit-agent.runtimeconfig.json" target="contentFiles/agents/netcoreapp3.1" />

I think this one's been missed, Charlie. (I also don't know why we use contentFiles instead of tools here, but keeping it consistent seems safest! 😅)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I initially tried to keep it consistent, but I got failures when I did that. However, I can now think of another reason for that, so I'll try again. If this were for 4.0, I'd say just drop the whole contentFiles thing unless somebody can say why.

src/NUnitEngine/mock-assembly-x86/mock-assembly-x86.csproj Outdated Show resolved Hide resolved
@ChrisMaddock
Copy link
Member

Ok - I think I've covered everything here.

I've resolved a few discussions that I think are sorted, and unresolved a couple that I think were missed. I've added a few new comments, almost entirely re: the new changes. I think I've also responded to all still-open conversations.

The x86 changes look good - glad finally we've got some tests around that too! In future, I'd like to add tests to mock-assembly which only pass if they are running on the targeted framework/architecture, so we can smoke test that functionality too.

Let me know if there's anything I've missed - let's get this merged! 😁

@CharliePoole
Copy link
Collaborator Author

CharliePoole commented May 2, 2021 via email

@ChrisMaddock
Copy link
Member

Thanks Charlie - and it is a lot to keep track of. Hopefully we'll catch most things between us!

I'd like to do that too, but when I took a casual look at the idea, it
seemed as if I would have to add more info to TestResult.xml to do that.

Ah - I was thinking more simply a test which fails when it's run on e.g. .NET 2.0, and using pre-compilation symbols to make sure the right version is included in the right assembly. That's what I do in my manual tests before releases. 🙂

@CharliePoole
Copy link
Collaborator Author

If I understand you, that would work if the test can run, e.g. net20 on net40. But if the test can't run at all, the package tests typically need to examine the TestResult file to find out why it failed. That's because we keep running subsequent tests rather than throwing immediately. I may be able to figure out a way to recognize that the test failed because the agent couldn't load it though.

@CharliePoole
Copy link
Collaborator Author

CharliePoole commented May 3, 2021

@ChrisMaddock This PR and reviews and comments on reviews etc. is getting a bit hard to follow. So to checkpoint where we are, here's a list of items you brought up, which I believe still need to be dealt with...

  • Figure out whether we need to package nunit-agent.deps.json. I have tests passing without it, but it won't hurt to add. We should either include it in all four packages or leave it out of all.

  • Decide about .addins files for agents. Given that we currently have no extensions of our own for .NET Core, we could just leave out the file. Or we could point to a directory that users can put things in... or... or... or... It would be nice if we didn't need to re-release the first time there's a .NET Core extension, although that's possible as well.

  • Decide whether to use contentFiles or tools for the .json files. My memory is that using contentFiles didn't work, but I'll retest that.

  • For mock-assembly, I'll test out your idea of just including the files in the parent dir without a link.

  • Check whether various references and package references are really needed for the tests to pass. I'm a little vague here because you hadn't followed up to some of my responses. Basically, however, I think we need to leave in any references if the tests start to fail when I remove them. It may be that this works differently if I include .deps.json, so I'll try with and without. That said, at some future point it would help if you could write something about why those package refs and refs ought to be removed. Maybe that should be a 4.0 issue.

  • Remove extra checks from RuntimeFrameworkService.FrameworksMatch

  • Re-examine default behavior in RuntimeFrameworkService.SelectRuntime when no RuntimeTargetAttribute is present.

Let me know if I've missed something. 😃

@ChrisMaddock
Copy link
Member

That looks about right to me! 👍

  1. I'm in favour of taking the easy way out for the msi, and just removing the file until we have extensions to go with it.
  2. I did try myself this before suggesting, and it seemed to work for me. 🙂 (Same suggestion for the new nunit-agent projects, too!)
  3. Can you highlight to me which responses I've missed? I think this covers two separate issues:
    5a. The references added to nunit.engine.core.csproj, which I believe are just a rebase error as I'd just removed those from master recently.
    5b. The reference added to nunit.engine.tests.csproj, and the new app.config added to the nunit-3console.tests project. Both of these - I'm unclear on why the tests have been passing previously (I think!), and why they're now needed. Would appreciate your thoughts there.

@CharliePoole
Copy link
Collaborator Author

@ChrisMaddock Regarding (5) I probably didn't make myself clear. It's not a rebase error. I saw that you had removed them and I had to put them back in to the package tests for .NET Core to pass. There was no failure before because we didn't have such a test or even a .NET Core agent to fail!

That said, I'm taking on trying again without them and seeing if this interacts with the presence or absence of `nunit-agent.deps.json'. I think this is something we really need to understand better.

@CharliePoole
Copy link
Collaborator Author

Should be ready to go now. I think we have a number of packaging decisions to make for 4.0, however.

@ChrisMaddock
Copy link
Member

Great, thanks for getting those sorted! Afraid there's a couple of things in the last commit I still think need looking at.

  1. The latest commit has added nunit-agent.runtimeconfig.dev.json to the packages, rather than nunit-agent.deps.json. I presume that was unintentional, as you'd put deps.json in your list above? The "dev" file I believe is for development only.

  2. Sorry, we've miscommunicated around the .addins files. By my suggestion, I was only meaning removing it from the msi, as we know that there are no .NET Core compatible extension assemblies installed with the msi. I see the last commit also removes it from the NuGet packages. I think the NuGet version needs to stay I'm afraid, I know that's currently used at least for the TeamCity extension.

Let me know if there's anything we need to discuss further - otherwise please go ahead and merge once the changes are in. Thanks for all your work getting it sorted! 😄

@CharliePoole
Copy link
Collaborator Author

I'm afraid I thought I was doing what you wanted without really understanding why you wanted it. I'll take the blame for that choice. In future, I think it would help to have failing scenarios that force us to add something to the packages. After all, that's why we have package tests.

I'll make the changes in the morning.

@ChrisMaddock
Copy link
Member

Great - thanks for this Charlie! One step closer to where we want to be! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants