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

CSHARP-4420: EG tests for Atlas Search #1001

Closed
wants to merge 21 commits into from

Conversation

BorisDog
Copy link
Contributor

@BorisDog BorisDog commented Dec 22, 2022

This PR is rebased on top of CSHARP-4440.
The main focus here is AtlasSearchTest.cs
Please review just the last commit.

BorisDog and others added 20 commits December 2, 2022 10:04
@JamesKovacs JamesKovacs requested review from DmitryLukyanov and removed request for JamesKovacs January 6, 2023 01:44
Copy link

@DmitryLukyanov DmitryLukyanov left a 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.

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

Copy link
Contributor Author

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.

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

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 =

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

Copy link
Contributor Author

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[]

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?

Copy link
Contributor Author

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.

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.

Copy link
Contributor

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()

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

Copy link
Contributor Author

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?

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()

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

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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.

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:

  1. Better to use target settings approach like: --target=$TARGET that works on both windows and non windows machines
  2. 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

Copy link
Contributor Author

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

Copy link
Contributor

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.

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

Copy link
Contributor

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

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

Copy link
Contributor Author

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; }

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?

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?

Copy link
Contributor Author

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() =>

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();

Copy link
Contributor Author

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)

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();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link

@DmitryLukyanov DmitryLukyanov left a 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()

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

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:

  1. Better to use target settings approach like: --target=$TARGET that works on both windows and non windows machines
  2. 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.

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.

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>());

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

Copy link
Contributor Author

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[]

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.

Copy link

@DmitryLukyanov DmitryLukyanov left a comment

Choose a reason for hiding this comment

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

LGTM

@rstam rstam self-requested a review January 12, 2023 15:38
Copy link
Contributor

@rstam rstam left a 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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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[]
Copy link
Contributor

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.

@BorisDog BorisDog closed this Jan 19, 2023
@BorisDog BorisDog deleted the csharp4420 branch January 19, 2023 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants