-
Notifications
You must be signed in to change notification settings - Fork 521
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
Split redis tests into separate test assembly #4468
Conversation
@@ -18,6 +18,7 @@ | |||
|
|||
<ItemGroup> | |||
<InternalsVisibleTo Include="Aspire.Hosting.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.
We should aim to remove this.
tests/Aspire.Hosting.Tests/Containers/ContainerResourceBuilderTests.cs
Outdated
Show resolved
Hide resolved
public class RedisFunctionalTests | ||
{ | ||
[Fact] | ||
public async Task VerifyRedisResource() |
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.
cc @eerhardt @radical @ReubenBond @mitchdenny thoughts?
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 test adds value over top of the other Redis Hosting tests, since it actually connects a client to it.
It seems like a "middle of the ground" test. Not a unit test, but not a full end-to-end functional test like
aspire/tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs
Lines 32 to 53 in 8e311f3
[InlineData(TestResourceNames.redis)] | |
[InlineData(TestResourceNames.garnet)] | |
[InlineData(TestResourceNames.valkey)] | |
[InlineData(TestResourceNames.sqlserver)] | |
[InlineData(TestResourceNames.milvus)] | |
public Task VerifyComponentWorks(TestResourceNames resourceName) | |
=> RunTestAsync(async () => | |
{ | |
_integrationServicesFixture.EnsureAppHasResources(resourceName); | |
try | |
{ | |
var response = await _integrationServicesFixture.IntegrationServiceA.HttpGetAsync("http", $"/{resourceName}/verify"); | |
var responseContent = await response.Content.ReadAsStringAsync(); | |
Assert.True(response.IsSuccessStatusCode, responseContent); | |
} | |
catch | |
{ | |
await _integrationServicesFixture.DumpComponentLogsAsync(resourceName, _testOutput); | |
throw; | |
} | |
}); |
It is definitely simpler than the end-to-end 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 like these tests, they are a good smoke test. I do think they need to be broken up though. That way if I've made some changes in "redis" land I can run everything related to Redis just by pointing at a particular test assembly.
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 it's testing less than the current E2E tests, at least when looking from the Redis POV. The E2E is only creating a distinct web api project to use the component, that's the difference with this local functional test.
Do we still need the Redis portion of the E2E test if so? Or should we extract the current portion of the E2E test into a separate project?
For instance, could we not add more volumes testing with this new functional test project already?
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 it's testing less than the current E2E tests
The part that the current E2E tests cover that aren't covered here is the "WithReference" portion that connects a separate project with a resource. This is being simulated in the current test with:
hb.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["ConnectionStrings:redis"] = await redis.Resource.GetConnectionStringAsync()
});
Do we still need the Redis portion of the E2E test if so? Or should we extract the current portion of the E2E test into a separate project?
I think once we have all the AppHost resource tests split into separate test assemblies, and FunctionalTests like this one for each resource, we can remove the bulk of the resources from the E2E test, and only keep maybe ~5 core resources being tested there. That way when a new resource/component gets added we don't need to update the E2E test and have it continually grow, like it is doing today.
tests/Aspire.Hosting.Redis.Tests/Aspire.Hosting.Redis.Tests.csproj
Outdated
Show resolved
Hide resolved
# Conflicts: # Aspire.sln # src/Aspire.Hosting/Aspire.Hosting.csproj # tests/Aspire.Hosting.Containers.Tests/ContainerResourceBuilderTests.cs
Otherwise would try to run it on Windows in CI where Docker is not available
Added some tests for |
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=726269&view=codecoverage-tab |
Nothing works anymore, checking the simplest one for conflicts
@sebastienros - it looks like the tests are still failing |
|
At least that was the case with the first attempt. I'm not sure about the second one because this shows |
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.
Maybe we should split this apart and add the Volume/BindMount tests in a separate PR?
@@ -22,6 +22,7 @@ | |||
|
|||
<ItemGroup> | |||
<InternalsVisibleTo Include="Aspire.Hosting.Tests" /> | |||
<InternalsVisibleTo Include="Aspire.Hosting.Redis.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.
@sebastienros - can we remove this? What is it needed 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.
RedisContainerImageTags
RedisCommanderConfigWriterHook
Are used in these tests and internal.
This is why Aspire.Hosting.Tests
was already listed, because these tests are coming from this project (moved to this new Aspire.Hosting.Redis.Tests
)
var redis = builder.AddRedis("redis").WithImageTag("7.1"); | ||
Assert.Equal("7.1", redis.Resource.Annotations.OfType<ContainerImageAnnotation>().Single().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.
Should this be reverted? Why it is using Redis in the core "Hosting.Containers" 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.
Reverted
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.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.
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" /> | |
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" IsAspireProjectResource="false" /> | |
<ProjectReference Include="..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" /> | |
<ProjectReference Include="..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" /> |
Are these needed? This project doesn't have <IsAspireHost>true</IsAspireHost>
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.
Works as you suggest
|
||
await VerifyDataPersistence( | ||
options => options.WithDataVolume(volumeName).WithPersistence(snapshotInterval), | ||
async redisClient => await Task.Delay(snapshotInterval + TimeSpan.FromSeconds(1)) |
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 seems like it will be flaky - especially on slow machines.
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 ok to remove it, as long as we agree that the other explicit SAVE call is sufficient to test the functionality since we already have a unit test that ensures the correct --save
argument is passed with a custom timespan. This test is only validating that the feature actually works in Redis. Or we can add more that "1 more second after the time that Redis should have saved it".
@@ -169,7 +171,10 @@ public async Task SingleRedisInstanceProducesCorrectRedisHostsVariable(string co | |||
|
|||
var commander = builder.Resources.Single(r => r.Name.EndsWith("-commander")); | |||
|
|||
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(commander, DistributedApplicationOperation.Run, TestServiceProvider.Instance); | |||
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync( |
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.
Line too long couldn't read the code.
Assert.True(value.IsNull); | ||
} | ||
|
||
await app.StopAsync(); |
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 required with AttemptDeleteDockerVolume
as otherwise the container is still running until the test is done, and holds a ref to it. Also the two containers exist concurrently without it.
I would expect app.Dispose
to call StopAsync
but it's not the case.
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 expect app.Dispose to call StopAsync but it's not the case.
I would expect the same thing. @mitchdenny - is this a bug in DistributedApplication?
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@sebastienros looks like the restructured tests are failing. |
@mitchdenny are you aware of #4786 ? |
I'm aware of that, although I think these test failures aren't related (I could be wrong). If they are then feel free to ignore, and obviously #4786 takes priority. |
I think it's related, last time I had the same issue I asked @radical and he showed me the throttling issue. Also these tests worked earlier when Eric triggered a new build (when the quotas got renewed apparently). But I'll check in the log to see if I can find a confirmation. |
Confirmed in the logs:
It's showing up first because it's a job before Helix runs, it's the first tests that try to download docker images. Then the Job is terminated. |
Initial stab at #4294.
I added solution folders for tests:
TODO:
Microsoft Reviewers: Open in CodeFlow