-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4420: EG tests for Atlas Search #1001
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some mostly minor comments
@@ -0,0 +1,79 @@ | |||
// Copyright 2010-present MongoDB Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright has a bit different commenting format, see other files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll fix this in the main search PR too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure whether it's already should be fixed, but if so - not fixed yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the future :( I would suggest using a different PR approach (we already did similar work in past) since it's hard to follow what was fixed and what should be reviewed. Sounds like at least in this file the above suggestion was applied..
[Trait("Category", "AtlasSearch")] | ||
public class AtlasSearchTest : LoggableTestClass | ||
{ | ||
private static readonly GeoJsonPolygon<GeoJson2DGeographicCoordinates> __testPolygon = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put static
fields into region static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
public class AtlasSearchTest : LoggableTestClass | ||
{ | ||
private static readonly GeoJsonPolygon<GeoJson2DGeographicCoordinates> __testPolygon = | ||
new(new(new(new GeoJson2DGeographicCoordinates[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no ideas what happens here =)) Can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a long chain of classes creation with long names shortened to omit the names for readability.
So for example in creation of GeoWithinBox
, the only important and visible data is its 2 corners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this feature. Sounds like it automatically recognizes which type is expected to be created and which arguments expected to be passed into. It looks "cute", but only until you really don't care about what actual types are needed to create the target type. Currently it might be true, next time it might be changed. It can be problematic especially if you're looking at the code from github.. I probably don't mind about it especially in a test like this, but I would use it carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit the names for readability
LOL.
I found it much harder to read because there is no way to know what each call to new
is doing without going into Visual Studio and hovering the mouse over each new
to see what it does.
I agree with Dima. This looks like an abuse of a new C# feature.
_disposableMongoClient.Dispose(); | ||
|
||
[Fact] | ||
public void Autocomplete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use more test related naming. At the very least: Autocomplete_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not big fun of having same prefix for all test methods, especially when it does not add any information. Can you think of other alternatives here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the very least it will allow to determine where actual method and where a test for this method in VS UI. Also you may look at best practice for testing here (search for Naming your tests
). As for example of a better name, it can be: Autocomplete should produce expected outcome(or how it's called?)
[Fact] | ||
public void MustNot() | ||
{ | ||
var result = SearchSingle(Builders.Search.Compound() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend better formatting here (and in other places), something like:
var result = SearchSingle(
Builders.Search.Compound().MustNot(
Builders.Search.Phrase("life, liberty", x => x.Body)));
result.Title.Should().Be("US Constitution");
or maybe better creating new variables for inner steps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
export ATLAS_SEARCH_TESTS_ENABLED=true | ||
|
||
powershell.exe .\\build.ps1 --target TestAtlasSearch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have plans for non windows envs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choice for Windows platform is arbitrary, but we don't plan to extend to other OS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, I wrote it for 2 reasons:
- Better to use target settings approach like:
--target=$TARGET
that works on both windows and non windows machines - powershell is only windows tool, so given you don't have validation on OS, potentially it might throw, but it's minor, see whether you want to change anything here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine for now, just copied from run-atlas-data-lake-test
and run-atlas-connectivity-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James told me once that we had to use --target=TestAtlasSearch
.
I.e. that the =
was mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's mandatory only on non windows OSs if I recall correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point it was mandatory on my Windows machine also, so I got used to using the =
form.
My guess is that at some point a Cake release made it mandatory, and they got lots of complaints, and then they reverted the change.
I'm assuming it's Cake that parses this argument(s) and not Powershell.
#!/usr/bin/env bash | ||
|
||
set -o xtrace | ||
set -o errexit # Exit the script with error if any of the commands fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a section like in most of other files about output variables: https://github.com/mongodb/mongo-csharp-driver/blob/master/evergreen/run-csfle-azure-tests.sh#L11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/// Gets or sets the document field which returned a match. | ||
/// </summary> | ||
[BsonElement("path")] | ||
public string Path { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why private set
is here? Sounds like it does nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like it's for deserialization only. Does it deserve a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's for deserialization. Looks pretty minor for a comment.
_disposableMongoClient = new(new MongoClient(atlasSearchUri), CreateLogger<DisposableMongoClient>()); | ||
} | ||
|
||
protected override void DisposeInternal() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think all content suites in one line like:
protected override void DisposeInternal() => _disposableMongoClient.Dispose();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
GetGeoTestCollection().Aggregate().Search(searchDefintion).ToList(); | ||
|
||
private HistoricalDocument SearchSingle(SearchDefinition<HistoricalDocument> searchDefintion) => | ||
GetTestCollection().Aggregate().Search(searchDefintion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be at least:
GetTestCollection().Aggregate().Search(searchDefintion)
.Limit(1)
.ToList()
.Single();
but I would recommend a better formatting:
GetTestCollection()
.Aggregate()
.Search(searchDefintion)
.Limit(1)
.ToList()
.Single();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some mostly minor comments
_disposableMongoClient.Dispose(); | ||
|
||
[Fact] | ||
public void Autocomplete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the very least it will allow to determine where actual method and where a test for this method in VS UI. Also you may look at best practice for testing here (search for Naming your tests
). As for example of a better name, it can be: Autocomplete should produce expected outcome(or how it's called?)
|
||
export ATLAS_SEARCH_TESTS_ENABLED=true | ||
|
||
powershell.exe .\\build.ps1 --target TestAtlasSearch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, I wrote it for 2 reasons:
- Better to use target settings approach like:
--target=$TARGET
that works on both windows and non windows machines - powershell is only windows tool, so given you don't have validation on OS, potentially it might throw, but it's minor, see whether you want to change anything here
@@ -0,0 +1,79 @@ | |||
// Copyright 2010-present MongoDB Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure whether it's already should be fixed, but if so - not fixed yet
@@ -0,0 +1,79 @@ | |||
// Copyright 2010-present MongoDB Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the future :( I would suggest using a different PR approach (we already did similar work in past) since it's hard to follow what was fixed and what should be reviewed. Sounds like at least in this file the above suggestion was applied..
var atlasSearchUri = Environment.GetEnvironmentVariable("ATLAS_SEARCH"); | ||
Ensure.IsNotNullOrEmpty(atlasSearchUri, nameof(atlasSearchUri)); | ||
|
||
_disposableMongoClient = new(new MongoClient(atlasSearchUri), CreateLogger<DisposableMongoClient>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest creating a new CreateDisposableClient(connectionString) method to DriverTestConfiguration to be able creating a test client in the same way across driver tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest doing this in different small refactoring PR, to change all other places too.
public class AtlasSearchTest : LoggableTestClass | ||
{ | ||
private static readonly GeoJsonPolygon<GeoJson2DGeographicCoordinates> __testPolygon = | ||
new(new(new(new GeoJson2DGeographicCoordinates[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this feature. Sounds like it automatically recognizes which type is expected to be created and which arguments expected to be passed into. It looks "cute", but only until you really don't care about what actual types are needed to create the target type. Currently it might be true, next time it might be changed. It can be problematic especially if you're looking at the code from github.. I probably don't mind about it especially in a test like this, but I would use it carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes requested. Overall looks good.
I think this needs to be reviewed again (in a new clean PR) once you have rebased this on the csharp4440 work.
|
||
export ATLAS_SEARCH_TESTS_ENABLED=true | ||
|
||
powershell.exe .\\build.ps1 --target TestAtlasSearch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James told me once that we had to use --target=TestAtlasSearch
.
I.e. that the =
was mandatory.
/// <summary> | ||
/// Represents a result of highlighting. | ||
/// </summary> | ||
public sealed class Highlight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this new file in this PR? Shouldn't all work that is not testing related be in the CSHARP-4440 PR?
In any case, I'm not reviewing this file in this PR because it's not testing related.
This whole folder is wildly out of date with CSHRP-4440.
namespace MongoDB.Driver.Tests.Search | ||
{ | ||
[Trait("Category", "AtlasSearch")] | ||
public class AtlasSearchTest : LoggableTestClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename file and class to AtlasSearchTests
(plural)
public class AtlasSearchTest : LoggableTestClass | ||
{ | ||
private static readonly GeoJsonPolygon<GeoJson2DGeographicCoordinates> __testPolygon = | ||
new(new(new(new GeoJson2DGeographicCoordinates[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit the names for readability
LOL.
I found it much harder to read because there is no way to know what each call to new
is doing without going into Visual Studio and hovering the mouse over each new
to see what it does.
I agree with Dima. This looks like an abuse of a new C# feature.
This PR is rebased on top of CSHARP-4440.
The main focus here is AtlasSearchTest.cs
Please review just the last commit.