Skip to content

CSHARP-4421: Unify all spec tests in single test project #977

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

Merged
merged 3 commits into from
Dec 8, 2022

Conversation

BorisDog
Copy link
Contributor

This is a prerequisite for both CSHARP-4422 and for Driver/Core unification.

@BorisDog BorisDog requested a review from JamesKovacs November 25, 2022 23:13
<EmbeddedResource LinkBase="Specifications\transactions-convenient-api" Include="..\..\specifications\transactions-convenient-api\**\*.json" />
<EmbeddedResource LinkBase="Specifications\unified-test-format" Include="..\..\specifications\unified-test-format\**\*.json" />
<EmbeddedResource LinkBase="Specifications\versioned-api" Include="..\..\specifications\versioned-api\**\*.json" />
<EmbeddedResource LinkBase="Specifications\" Include="..\..\specifications\**\*.json" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JamesKovacs no need to split to folders anymore :)
The downside is that GridFS tests are included as resources. I think we can ignore that for now.

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

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

Minor change requested. And please verify spec test counts are identical on EG before and after the reorganization and namespace changes.

return (IServerMonitor)Reflector.GetFieldValue(server, nameof(_monitor));
}
}

internal static class ServerMonitorReflector
{
public static IRoundTripTimeMonitor _roundTripTimeMonitor(this IServerMonitor serverMonitor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously the reflectors were only used in the file in which they were defined. Now they are split between two files. Let's move all reflectors to a Reflectors.cs file in this spec test folder.

Copy link
Contributor

Choose a reason for hiding this comment

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

Previously the reflectors were only used in the file in which they were defined

that's not really true. Mostly yes, but I think the idea is to define reflector in a class that suites most (ServerMonitorReflector in ServerMonitorTests, ServerReflector in ServerTests and etc) and reuse it in the rest of classes. But I agree for different reasons it worked not in all cases

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh no... let's not do that.

I'd rather reflectors stay in the one file were they are needed, and normally they'd be private, though sometimes public if we now and then need to call them from somewhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

The general rule should be that XyzReflector lives in the XyzTests.cs file.

Copy link
Contributor

Choose a reason for hiding this comment

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

The challenge here is that the same reflector is used in multiple test files. The other solution - which I'd be good with - is making the reflectors private to each file and duplicating the one Server._monitor method.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy with either proposed solution - duplicating or Reflectors.cs. I'll let @rstam chime in on his preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't really duplicate here (as reflectors are not private). So leave as is or Reflectors.cs (I got slight preference for Reflectors.cs but not a hard one).

Copy link
Contributor

Choose a reason for hiding this comment

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

The challenge here is that the same reflector is used in multiple test files.

Yet that's why reflectors are public.

I'd rather not have multiple reflectors for the same class if we can help it.

The problem here is that it's not XyzReflector and XyzTests.cs anymore

Why not? I don't see why we can't keep doing that.

So leave as is or Reflectors.cs

I have a preference for the current way. Reflectors.cs sounds like it's just going to be a giant grab bag of reflectors all in one source file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JamesKovacs are we good to keep the code as is now?
We probably should think of more creative approach for using reflection in tests in general, in particular to avoid cross dependency between test files.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can keep it as-is. I don't like the needed reflectors split between test files, but I don't see a better solution than this at the moment.

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

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

Minor change and then I think we are good to go. MockClusterableServerFactory.cs and MockConnection.cs moved to the Core.TestHelpers assembly but the namespace wasn't changed to match.

return (IServerMonitor)Reflector.GetFieldValue(server, nameof(_monitor));
}
}

internal static class ServerMonitorReflector
{
public static IRoundTripTimeMonitor _roundTripTimeMonitor(this IServerMonitor serverMonitor)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can keep it as-is. I don't like the needed reflectors split between test files, but I don't see a better solution than this at the moment.

Copy link
Contributor Author

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Tests count verified.

@BorisDog BorisDog requested a review from JamesKovacs December 7, 2022 21:51
Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

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

LGTM

@BorisDog BorisDog merged commit baffee0 into mongodb:master Dec 8, 2022
BorisDog added a commit to BorisDog/mongo-csharp-driver that referenced this pull request Dec 22, 2022
BorisDog added a commit to BorisDog/mongo-csharp-driver that referenced this pull request Jan 30, 2023
dnickless pushed a commit to dnickless/mongo-csharp-driver that referenced this pull request Aug 24, 2023
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.

4 participants