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

[tests] Refactor SqlServer tests to use testcontainers #3034

Merged
merged 23 commits into from
Mar 26, 2024

Conversation

radical
Copy link
Member

@radical radical commented Mar 20, 2024

Also add tracing tests for Aspire.Microsoft.Data.SqlClient.Tests

Microsoft Reviewers: Open in CodeFlow

@radical radical added testing ☑️ area-integrations Issues pertaining to Aspire Integrations packages labels Mar 20, 2024
@radical radical requested a review from eerhardt March 21, 2024 01:54
@radical radical marked this pull request as ready for review March 21, 2024 01:54
@radical
Copy link
Member Author

radical commented Mar 21, 2024

@eerhardt Are there any tests that I missed here?

@radical radical force-pushed the sqlserver-testcontainers branch from b88d79a to 26d02c8 Compare March 21, 2024 06:07
// TODO
protected override string[] RequiredLogCategories => Array.Empty<string>();
protected override string[] RequiredLogCategories => [
"Microsoft.Extensions.Hosting.Internal.ApplicationLifetime",
Copy link
Member

Choose a reason for hiding this comment

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

Were tests failing if we don't do this? We don't have these categories elsewhere.

The issue is that Microsoft.Data.SqlClient doesn't support logging. See Aspire.Microsoft.Data.SqlClient: in https://github.com/dotnet/aspire/blob/main/src/Components/Telemetry.md.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the tests weren't failing because they didn't check for any required categories.

From your link:

Aspire.Microsoft.EntityFrameworkCore.SqlServer:

Log categories:
"Microsoft.EntityFrameworkCore.ChangeTracking"
"Microsoft.EntityFrameworkCore.Database.Command"
"Microsoft.EntityFrameworkCore.Database.Connection"
"Microsoft.EntityFrameworkCore.Database.Transaction"
"Microsoft.EntityFrameworkCore.Infrastructure"
"Microsoft.EntityFrameworkCore.Migrations"
"Microsoft.EntityFrameworkCore.Model"
"Microsoft.EntityFrameworkCore.Model.Validation"
"Microsoft.EntityFrameworkCore.Query"
"Microsoft.EntityFrameworkCore.Update"

Shouldn't we check for these?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, you were talking about SqlClient:

Aspire.Microsoft.Data.SqlClient:
Log categories:
none (the client does not provide an easy way to integrate it with logger factory)

radical added 5 commits March 22, 2024 14:59
- move SqlServerContainerFixture to `Aspire.Microsoft.Data.SqlClient.Tests`
- Instead of using `InternalsVisibleTo`, compile the relevant file with
  the project.
…rumentation.SqlClient to Aspire.Microsoft.EntityFrameworkCore.SqlServer
@radical
Copy link
Member Author

radical commented Mar 22, 2024

I made the suggested changes. And also had to update ActivitySourceName:

-    protected override string ActivitySourceName => "OpenTelemetry.Instrumentation.SqlClient";
+    protected override string ActivitySourceName => "Aspire.Microsoft.Data.SqlClient";
-    protected override string ActivitySourceName => "OpenTelemetry.Instrumentation.SqlClient";
+    protected override string ActivitySourceName => "Aspire.Microsoft.EntityFrameworkCore.SqlServer";

does that change look correct?

@@ -71,5 +81,26 @@ protected override void SetMetrics(MicrosoftDataSqlClientSettings options, bool
=> options.Metrics = enabled;

protected override void TriggerActivity(SqlConnection service)
=> service.Open();
Copy link
Member

Choose a reason for hiding this comment

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

Was just opening a connection not enough to trigger an activity?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, nothing was emitted with just that, and the tests would fail:

[xUnit.net 00:00:23.52]     Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests.TracingEnablesTheRightActivitySource [FAIL]
  Failed Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests.TracingEnablesTheRightActivitySource [7 s]
  Error Message:
   Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Remote process failed with an unhandled exception.
  Stack Trace:

Child exception:
  Xunit.Sdk.NotEmptyException: Assert.NotEmpty() Failure
   at Aspire.Components.ConformanceTests.ConformanceTests`2.ActivitySourceTest(String key) in /Users/ankj/dev/a3/tests/Aspire.Components.Common.Tests/ConformanceTests.cs:line 405
   at Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests.<>c.<TracingEnablesTheRightActivitySource>b__24_1(ConformanceTests obj) in /Users/ankj/dev/a3/tests/Aspire.Microsoft.Data.SqlClient.Tests/ConformanceTests.cs:line 94
   at Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests.RunWithFixtureAsync(Action`1 test) in /Users/ankj/dev/a3/tests/Aspire.Microsoft.Data.SqlClient.Tests/ConformanceTests.cs:line 104
   at Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests.RunWithFixtureAsync(Action`1 test) in /Users/ankj/dev/a3/tests/Aspire.Microsoft.Data.SqlClient.Tests/ConformanceTests.cs:line 104
   at Microsoft.DotNet.RemoteExecutor.Program.Main(String[] args) in /_/src/Microsoft.DotNet.RemoteExecutor/src/Program.cs:line 65

Child process:
  Aspire.Microsoft.Data.SqlClient.Tests, Version=42.42.42.42, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 Aspire.Microsoft.Data.SqlClient.Tests.ConformanceTests+<>c System.Threading.Tasks.Task <TracingEnablesTheRightActivitySource>b__24_0()

@radical radical requested a review from eerhardt March 25, 2024 19:21
normj and others added 5 commits March 25, 2024 16:06
* Change how resources expose urls to the dashboard
- The resource server used to have a services and
endpoints split, that is now a single object called a url
which has a name, a full url (uri format) and a bool for
if that endpoint is internal (or an implementation detail).
- Clean up the way we extract urls from the dcp information by
mapping the app model resource and endpoint within each service
resource in DCP.
- Mark fields as deprecated in the proto file
- Moved from Tuples to records for CustomResourceSnapshot
* Enable basic certificate auth for resource service

This adds the ability to configured the gRPC connection from the dashboard to a resource service to use certificates for authentication.

Such auth is not used in the local dev scenario, so the app host is changed to suppress auth via the `DOTNET_RESOURCE_SERVICE_DISABLE_AUTH` environment variable. The dashboard will now require certificates unless this variable is set to `1`. This discourages self-hosting the dashboard in an insecure manner.

* Support loading client cert from keystore

* Use enum for resource service auth mode

* Dashboard web app supports OpenID Connect

* Use a single authentication call for both the web app and OTLP

Use explicit policies and configure those policies with the authentication schemes required.

Also rejig some config settings for consistency.

* Remove redundant configuration key

* Rename "web app" to "frontend"

* Reorder readme sections and adjust headings and their levels

* Seal class

* Simplify frontend auth implementation

* Add docs

* More thorough enum validation

* Remove unused config key

* Change exception type
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@eerhardt eerhardt merged commit c96e8e0 into dotnet:main Mar 26, 2024
8 checks passed
@radical radical deleted the sqlserver-testcontainers branch March 26, 2024 21:33
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages testing ☑️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants