Skip to content

Commit f71c302

Browse files
authored
Update to 8.0.4 of ASP.NET Core (#3667)
1 parent e2ba459 commit f71c302

File tree

6 files changed

+94
-43
lines changed

6 files changed

+94
-43
lines changed

eng/Versions.props

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>8.0.1</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
3939
<MicrosoftExtensionsOptionsPackageVersion>8.0.2</MicrosoftExtensionsOptionsPackageVersion>
4040
<MicrosoftExtensionsPrimitivesPackageVersion>8.0.0</MicrosoftExtensionsPrimitivesPackageVersion>
41-
<MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>8.0.3</MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>
42-
<MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>8.0.3</MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>
41+
<MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>8.0.4</MicrosoftAspNetCoreAuthenticationCertificatePackageVersion>
42+
<MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>8.0.4</MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion>
4343
<MicrosoftAspNetCoreOpenApiPackageVersion>8.0.4</MicrosoftAspNetCoreOpenApiPackageVersion>
44-
<MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>8.0.3</MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>
45-
<MicrosoftExtensionsCachingStackExchangeRedisPackageVersion>8.0.3</MicrosoftExtensionsCachingStackExchangeRedisPackageVersion>
46-
<MicrosoftExtensionsDiagnosticsHealthChecksEntityFrameworkCorePackageVersion>8.0.3</MicrosoftExtensionsDiagnosticsHealthChecksEntityFrameworkCorePackageVersion>
47-
<MicrosoftExtensionsDiagnosticsHealthChecksPackageVersion>8.0.3</MicrosoftExtensionsDiagnosticsHealthChecksPackageVersion>
48-
<MicrosoftExtensionsFeaturesPackageVersion>8.0.3</MicrosoftExtensionsFeaturesPackageVersion>
44+
<MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>8.0.4</MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion>
45+
<MicrosoftExtensionsCachingStackExchangeRedisPackageVersion>8.0.4</MicrosoftExtensionsCachingStackExchangeRedisPackageVersion>
46+
<MicrosoftExtensionsDiagnosticsHealthChecksEntityFrameworkCorePackageVersion>8.0.4</MicrosoftExtensionsDiagnosticsHealthChecksEntityFrameworkCorePackageVersion>
47+
<MicrosoftExtensionsDiagnosticsHealthChecksPackageVersion>8.0.4</MicrosoftExtensionsDiagnosticsHealthChecksPackageVersion>
48+
<MicrosoftExtensionsFeaturesPackageVersion>8.0.4</MicrosoftExtensionsFeaturesPackageVersion>
4949
<!-- EF -->
5050
<MicrosoftEntityFrameworkCoreCosmosPackageVersion>8.0.4</MicrosoftEntityFrameworkCoreCosmosPackageVersion>
5151
<MicrosoftEntityFrameworkCoreDesignPackageVersion>8.0.4</MicrosoftEntityFrameworkCoreDesignPackageVersion>

tests/Aspire.Components.Common.Tests/ActivityNotifier.cs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Runtime.CompilerServices;
6+
using System.Threading.Channels;
57
using OpenTelemetry;
68

79
namespace Aspire.Components.Common.Tests;
@@ -11,19 +13,44 @@ namespace Aspire.Components.Common.Tests;
1113
/// </summary>
1214
public sealed class ActivityNotifier : BaseProcessor<Activity>
1315
{
14-
// RunContinuationsAsynchronously because OnEnd gets invoked on the thread creating the Activity.
15-
// Running more test code on this thread can cause deadlocks in the case where the Activity is created on a "drain thread" (ex. Redis)
16-
// and the test method disposes the Host on that same thread. Disposing the Host will dispose the Instrumentation, which tries joining
17-
// with the "drain thread".
18-
private readonly TaskCompletionSource _taskSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
16+
private readonly Channel<Activity> _activityChannel = Channel.CreateUnbounded<Activity>();
1917

20-
public Task ActivityReceived => _taskSource.Task;
18+
public async Task<List<Activity>> TakeAsync(int count, TimeSpan timeout)
19+
{
20+
var activityList = new List<Activity>();
21+
using var cts = new CancellationTokenSource(timeout);
22+
await foreach (var activity in WaitAsync(cts.Token))
23+
{
24+
activityList.Add(activity);
25+
if (activityList.Count == count)
26+
{
27+
break;
28+
}
29+
}
2130

22-
public List<Activity> ExportedActivities { get; } = [];
31+
return activityList;
32+
}
2333

2434
public override void OnEnd(Activity data)
2535
{
26-
ExportedActivities.Add(data);
27-
_taskSource.SetResult();
36+
_activityChannel.Writer.TryWrite(data);
37+
}
38+
39+
private async IAsyncEnumerable<Activity> WaitAsync([EnumeratorCancellation] CancellationToken cancellationToken)
40+
{
41+
await foreach (var activity in _activityChannel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false))
42+
{
43+
yield return activity;
44+
}
45+
}
46+
47+
protected override void Dispose(bool disposing)
48+
{
49+
if (disposing)
50+
{
51+
_activityChannel.Writer.TryComplete();
52+
}
53+
54+
base.Dispose(disposing);
2855
}
2956
}

tests/Aspire.NATS.Net.Tests/AspireNatsClientExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void NatsInstrumentationEndToEnd()
184184

185185
builder.AddNatsClient(DefaultConnectionName);
186186

187-
var notifier = new ActivityNotifier();
187+
using var notifier = new ActivityNotifier();
188188
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddProcessor(notifier));
189189

190190
using var host = builder.Build();
@@ -193,10 +193,10 @@ public void NatsInstrumentationEndToEnd()
193193
var nats = host.Services.GetRequiredService<INatsConnection>();
194194
await nats.PublishAsync("test");
195195

196-
await notifier.ActivityReceived.WaitAsync(TimeSpan.FromSeconds(10));
197-
Assert.Single(notifier.ExportedActivities);
196+
var activityList = await notifier.TakeAsync(1, TimeSpan.FromSeconds(10));
197+
Assert.Single(activityList);
198198

199-
var activity = notifier.ExportedActivities[0];
199+
var activity = activityList[0];
200200
Assert.Equal("test publish", activity.OperationName);
201201
Assert.Contains(activity.Tags, kvp => kvp.Key == "messaging.system" && kvp.Value == "nats");
202202
}, _connectionString).Dispose();

tests/Aspire.StackExchange.Redis.DistributedCaching.Tests/DistributedCacheConformanceTests.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void WorksWithOpenTelemetryTracing()
4848

4949
builder.AddRedisDistributedCache("redis");
5050

51-
var notifier = new ActivityNotifier();
51+
using var notifier = new ActivityNotifier();
5252
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddProcessor(notifier));
5353
// set the FlushInterval to to zero so the Activity gets created immediately
5454
builder.Services.Configure<StackExchangeRedisInstrumentationOptions>(options => options.FlushInterval = TimeSpan.Zero);
@@ -61,14 +61,26 @@ public void WorksWithOpenTelemetryTracing()
6161
var cache = host.Services.GetRequiredService<IDistributedCache>();
6262
await cache.GetAsync("myFakeKey", CancellationToken.None);
6363

64-
// wait for the Activity to be processed
65-
await notifier.ActivityReceived.WaitAsync(TimeSpan.FromSeconds(10));
66-
67-
Assert.Single(notifier.ExportedActivities);
68-
69-
var activity = notifier.ExportedActivities[0];
70-
Assert.Equal("HMGET", activity.OperationName);
71-
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
64+
// read the first 3 activities
65+
var activityList = await notifier.TakeAsync(3, TimeSpan.FromSeconds(10));
66+
Assert.Equal(3, activityList.Count);
67+
Assert.Collection(activityList,
68+
// https://github.com/dotnet/aspnetcore/pull/54239 added 2 CLIENT activities on the first call
69+
activity =>
70+
{
71+
Assert.Equal("CLIENT", activity.OperationName);
72+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
73+
},
74+
activity =>
75+
{
76+
Assert.Equal("CLIENT", activity.OperationName);
77+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
78+
},
79+
activity =>
80+
{
81+
Assert.Equal("HMGET", activity.OperationName);
82+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
83+
});
7284
}, ConnectionString).Dispose();
7385
}
7486
}

tests/Aspire.StackExchange.Redis.OutputCaching.Tests/OutputCacheConformanceTests.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void WorksWithOpenTelemetryTracing()
4848

4949
builder.AddRedisOutputCache("redis");
5050

51-
var notifier = new ActivityNotifier();
51+
using var notifier = new ActivityNotifier();
5252
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddProcessor(notifier));
5353
// set the FlushInterval to to zero so the Activity gets created immediately
5454
builder.Services.Configure<StackExchangeRedisInstrumentationOptions>(options => options.FlushInterval = TimeSpan.Zero);
@@ -61,14 +61,26 @@ public void WorksWithOpenTelemetryTracing()
6161
var cacheStore = host.Services.GetRequiredService<IOutputCacheStore>();
6262
await cacheStore.GetAsync("myFakeKey", CancellationToken.None);
6363

64-
// wait for the Activity to be processed
65-
await notifier.ActivityReceived.WaitAsync(TimeSpan.FromSeconds(10));
66-
67-
Assert.Single(notifier.ExportedActivities);
68-
69-
var activity = notifier.ExportedActivities[0];
70-
Assert.Equal("GET", activity.OperationName);
71-
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
64+
// read the first 3 activities
65+
var activityList = await notifier.TakeAsync(3, TimeSpan.FromSeconds(10));
66+
Assert.Equal(3, activityList.Count);
67+
Assert.Collection(activityList,
68+
// https://github.com/dotnet/aspnetcore/pull/54239 added 2 CLIENT activities on the first call
69+
activity =>
70+
{
71+
Assert.Equal("CLIENT", activity.OperationName);
72+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
73+
},
74+
activity =>
75+
{
76+
Assert.Equal("CLIENT", activity.OperationName);
77+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
78+
},
79+
activity =>
80+
{
81+
Assert.Equal("GET", activity.OperationName);
82+
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
83+
});
7284
}, ConnectionString).Dispose();
7385
}
7486
}

tests/Aspire.StackExchange.Redis.Tests/AspireRedisExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public void KeyedServiceRedisInstrumentationEndToEnd()
265265
new KeyValuePair<string, string?>("ConnectionStrings:redis", connectionString)
266266
]);
267267

268-
var notifier = new ActivityNotifier();
268+
using var notifier = new ActivityNotifier();
269269
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddProcessor(notifier));
270270
// set the FlushInterval to to zero so the Activity gets created immediately
271271
builder.Services.Configure<StackExchangeRedisInstrumentationOptions>(options => options.FlushInterval = TimeSpan.Zero);
@@ -281,11 +281,11 @@ public void KeyedServiceRedisInstrumentationEndToEnd()
281281
var database = connectionMultiplexer.GetDatabase();
282282
database.StringGet("key");
283283

284-
await notifier.ActivityReceived.WaitAsync(TimeSpan.FromSeconds(10));
284+
// read the first activity
285+
var activityList = await notifier.TakeAsync(1, TimeSpan.FromSeconds(10));
286+
Assert.Single(activityList);
285287

286-
Assert.Single(notifier.ExportedActivities);
287-
288-
var activity = notifier.ExportedActivities[0];
288+
var activity = activityList[0];
289289
Assert.Equal("GET", activity.OperationName);
290290
Assert.Contains(activity.Tags, kvp => kvp.Key == "db.system" && kvp.Value == "redis");
291291
}, ConnectionString).Dispose();

0 commit comments

Comments
 (0)