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

Catastrophic failures when upgraded to v3 #435

Closed
bbascarevic opened this issue Jan 6, 2025 · 4 comments
Closed

Catastrophic failures when upgraded to v3 #435

bbascarevic opened this issue Jan 6, 2025 · 4 comments

Comments

@bbascarevic
Copy link

I'm on xUnit v2.9.2 and I upgraded xunit.runner.visualstudio from 2.8.2 to 3.0.0. I'm now getting these messages when running dotnet test from the console:

[xUnit.net 00:00:00.11]     [FATAL ERROR] System.InvalidOperationException
[xUnit.net 00:00:00.11]       System.InvalidOperationException : Key '586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6' already exists in the message metadata cache.
[xUnit.net 00:00:00.11]       Old item: TestCollectionStarting("586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6") name="" class=null
[xUnit.net 00:00:00.11]       New item: TestCollectionStarting("586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6") name="" class=null
[xUnit.net 00:00:00.11] Catastrophic failure: System.InvalidOperationException : Key '586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6' already exists in the message metadata cache.
Old item: TestCollectionStarting("586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6") name="" class=null
New item: TestCollectionStarting("586d9f8cc375d7e88d0d36659e3d796fc5a0dcd0416faab7d08903c0ce5372d6") name="" class=null

The same errors are appearing for TestCollectionStarting and TestClassStarting. All tests complete normally and report no failures despite these messages.

Is the v3 runner supposed to be used only with xUnit v3?
What does the error mean? I'm using my own discoverer, executor and runner but I don't know what is this "message metadata cache". Where do I start looking?

@bbascarevic
Copy link
Author

One more thing, my discoverer really is reporting multiple IXunitTestCases for the same test class, however each reported instance has different TestMethodArguments, like theories do, and each has a different UniqueID.

@bbascarevic
Copy link
Author

bbascarevic commented Jan 6, 2025

It seems that the issue is in Xunit2MessageAdapter.UniqueIDForTestCollection:

private static string UniqueIDForTestCollection(string assemblyUniqueID, Xunit.Abstractions.ITestCollection testCollection)
{
  return UniqueIDGenerator.ForTestCollection(assemblyUniqueID, testCollection.DisplayName, testCollection.CollectionDefinition?.Name);
}

The implementation uses the collection's DisplayName for deriving a unique ID, not the ITestCollection.UniqueID despite its definition:

/// <summary>
/// Gets the test collection ID. Test collection equality is determined by comparing IDs.
/// </summary>
Guid UniqueID { get; }

My collections had unique UniqueIds but not their display names (null).

So in short, collections need to have unique DisplayName values and their UniqueID seems to be ignored. Making collection display names unique made all the other catastrophic failures go away (TestClassStarting, etc.).

@bradwilson
Copy link
Member

Yes, there is an unstated part of the contract for test collection display names that they are unique, due to the way [Collection] works. Simulating it with unexpected data isn't something that we support. This is true whether the project is v2 or v3 (as the v2 adapter is using the same logic that v3 uses).

@bradwilson
Copy link
Member

Closing as "by design".

@bradwilson bradwilson closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants