-
Notifications
You must be signed in to change notification settings - Fork 462
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
Extract Aspire.Hosting.MySql.Tests #4925
Conversation
17e9c0c
to
b8bfeb7
Compare
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.
Can we also remove MySql from the EndToEnd tests?
If we do, we should probably have 2 functional tests - one for the non-EF component and one for the EF component. It could be in a single test if we wanted.
<Compile Include="$(SharedDir)SecretsStore.cs" Link="Utils\SecretsStore.cs" /> | ||
<Compile Include="$(RepoRoot)src\Aspire.Hosting\ApplicationModel\UserSecretsParameterDefault.cs" Link="Utils\UserSecretsParameterDefault.cs" /> |
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.
What are these for?
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.
There are tests checking that this is the type of credential that is created with the resource.
For all DBs btw.
AddMySqlAddsGeneratedPasswordParameterWithUserSecretsParameterDefaultInRunMode
AddMySqlDoesNotAddGeneratedPasswordParameterWithUserSecretsParameterDefaultInPublishMode
These are adapted though since the actual instance type is from the internal type in the Hosting assembly, and not the local one. What would solve it would be to make the type public.
@@ -59,6 +57,7 @@ | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Nats\NatsContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Milvus\MilvusContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MongoDB\MongoDBContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MySql\MySqlContainerImageTags.cs" /> |
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.
What is this still used for? It seems like it should be removed. Aspire.Hosting.Tests
shouldn't need to be testing all the extension resources we create.
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.
VerifyTestProgramFullManifest
checks a manifest which has all these resources, and uses
"image": "{{TestConstants.AspireTestContainerRegistry}}/{{MySqlContainerImageTags.Image}}:{{MySqlContainerImageTags.Tag}}",
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 this line should be removed.
|
# Conflicts: # Aspire.sln
# Conflicts: # Aspire.sln
<ItemGroup> | ||
<Compile Include="$(SharedDir)SecretsStore.cs" Link="Utils\SecretsStore.cs" /> | ||
<Compile Include="$(RepoRoot)src\Aspire.Hosting\ApplicationModel\UserSecretsParameterDefault.cs" Link="Utils\UserSecretsParameterDefault.cs" /> | ||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Testing\ResourceLoggerForwarderService.cs" Link="Utils\ResourceLoggerForwarderService.cs" /> |
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 don't think we should be compiling this into our tests. If we need this, we should just reference Aspire.Hosting.Testing.
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.
Applied in another PR, copied here.
<ProjectReference Include="..\..\src\Aspire.Hosting.Nats\Aspire.Hosting.Nats.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\..\src\Aspire.Hosting.Testing\Aspire.Hosting.Testing.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\testproject\TestProject.AppHost\TestProject.AppHost.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\Aspire.Hosting.Tests.SharedShim\Aspire.Hosting.Tests.SharedShim.csproj" IsAspireProjectResource="false" Aliases="AspireHostingShared" /> | ||
<ProjectReference Include="..\..\src\Components\Aspire.Microsoft.Data.SqlClient\Aspire.Microsoft.Data.SqlClient.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\..\src\Components\Aspire.MongoDB.Driver\Aspire.MongoDB.Driver.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\..\src\Components\Aspire.Npgsql\Aspire.Npgsql.csproj" IsAspireProjectResource="false" /> |
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 are we adding Npgsql in a MySql PR?
I think this should be removed.
@@ -59,6 +57,7 @@ | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Nats\NatsContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.Milvus\MilvusContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MongoDB\MongoDBContainerImageTags.cs" /> | |||
<Compile Include="$(RepoRoot)src\Aspire.Hosting.MySql\MySqlContainerImageTags.cs" /> |
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 this line should be removed.
[$"ConnectionStrings:{db.Resource.Name}"] = await db.Resource.ConnectionStringExpression.GetValueAsync(default) | ||
}); | ||
|
||
hb.AddMySqlDataSource(db.Resource.Name); |
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.
Should we also have tests that use the EF component? That way we can remove MySql from the EndToEnd tests completely and not lose coverage.
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.
Moved the EF tests here. Very similar to the one I did with Oracle (creating the tables using EF too, not just a SELECT 1
like in E2E).
var password = "p@ssw0rd1"; | ||
|
||
var passwordParameter = builder1.AddParameter("pwd"); | ||
builder1.Configuration["Parameters:pwd"] = password; | ||
var mysql1 = builder1.AddMySql("mysql", passwordParameter).WithEnvironment("MYSQL_DATABASE", mySqlDbName); |
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.
Instead of hard-coding a password (and cause more cred scan issues), can we use ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter
instead?
aspire/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs
Lines 140 to 162 in e38416a
/// <summary> | |
/// Creates a default password parameter that generates a random password. | |
/// </summary> | |
/// <param name="builder">Distributed application builder</param> | |
/// <param name="name">Name of parameter resource</param> | |
/// <param name="lower"><see langword="true" /> if lowercase alphabet characters should be included; otherwise, <see langword="false" />.</param> | |
/// <param name="upper"><see langword="true" /> if uppercase alphabet characters should be included; otherwise, <see langword="false" />.</param> | |
/// <param name="numeric"><see langword="true" /> if numeric characters should be included; otherwise, <see langword="false" />.</param> | |
/// <param name="special"><see langword="true" /> if special characters should be included; otherwise, <see langword="false" />.</param> | |
/// <param name="minLower">The minimum number of lowercase characters in the result.</param> | |
/// <param name="minUpper">The minimum number of uppercase characters in the result.</param> | |
/// <param name="minNumeric">The minimum number of numeric characters in the result.</param> | |
/// <param name="minSpecial">The minimum number of special characters in the result.</param> | |
/// <returns>The created <see cref="ParameterResource"/>.</returns> | |
/// <remarks> | |
/// To ensure the generated password has enough entropy, see the remarks in <see cref="GenerateParameterDefault"/>.<br/> | |
/// The value will be saved to the app host project's user secrets store when <see cref="DistributedApplicationExecutionContext.IsRunMode"/> is <c>true</c>. | |
/// </remarks> | |
public static ParameterResource CreateDefaultPasswordParameter( | |
IDistributedApplicationBuilder builder, string name, | |
bool lower = true, bool upper = true, bool numeric = true, bool special = true, | |
int minLower = 0, int minUpper = 0, int minNumeric = 0, int minSpecial = 0) | |
{ |
@eerhardt @radical fyi what was making the only test to fail was to use a bindmountpath which was not created before the container starts. It seems some containers are fine with that (Kafka?). But this would work locally just fine. Maybe some other kind of permissions, where locally the instance can create the folder, but not on the CI. |
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.
Other than the one comment, LGTM 👍
.AddRetry(new() { MaxRetryAttempts = 10, BackoffType = DelayBackoffType.Linear, Delay = TimeSpan.FromSeconds(2), ShouldHandle = new PredicateBuilder().Handle<MySqlException>() }) | ||
.Build(); | ||
|
||
var bindMountPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); |
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.
Would it be better to use Directory.CreateTempSubdirectory().FullName
here too, and skip the need to delete+create the directory below?
* Extract Aspire.Hosting.MySql.Tests * Improve reliability * Record Docker logs * Fix ResourceLoggerForwarderService link in Aspire.Hosting.PostgreSQL.csproj * Remove E2E tests * Fix manifest test * Fix tests * Increase delay between retries * Create mount path directory * Address PR feedback * Use Directory.Delete * Use Linear backoff --------- Co-authored-by: Ankit Jain <[email protected]> Co-authored-by: Eric Erhardt <[email protected]> (cherry picked from commit 5238a73)
Contributes to #4294
Microsoft Reviewers: Open in CodeFlow