-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test classes * change filename --------- Co-authored-by: Aaron Powell <[email protected]>
- Loading branch information
1 parent
bd5e72f
commit 98dc9c9
Showing
15 changed files
with
1,071 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copied from https://github.com/dotnet/aspire/blob/b51d08a617a60ae30f8305d98f1e34e1ed90da1a/tests/Aspire.Components.Common.Tests/ActivityNotifier.cs | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Channels; | ||
using OpenTelemetry; | ||
|
||
namespace Aspire.Components.Common.Tests; | ||
|
||
/// <summary> | ||
/// An OpenTelemetry processor that can notify callers when it has processed an Activity. | ||
/// </summary> | ||
public sealed class ActivityNotifier : BaseProcessor<Activity> | ||
{ | ||
private readonly Channel<Activity> _activityChannel = Channel.CreateUnbounded<Activity>(); | ||
|
||
public async Task<List<Activity>> TakeAsync(int count, TimeSpan timeout) | ||
{ | ||
var activityList = new List<Activity>(); | ||
using var cts = new CancellationTokenSource(timeout); | ||
await foreach (var activity in WaitAsync(cts.Token)) | ||
{ | ||
activityList.Add(activity); | ||
if (activityList.Count == count) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return activityList; | ||
} | ||
|
||
public override void OnEnd(Activity data) | ||
{ | ||
_activityChannel.Writer.TryWrite(data); | ||
} | ||
|
||
private async IAsyncEnumerable<Activity> WaitAsync([EnumeratorCancellation] CancellationToken cancellationToken) | ||
{ | ||
await foreach (var activity in _activityChannel.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false)) | ||
{ | ||
yield return activity; | ||
} | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
_activityChannel.Writer.TryComplete(); | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.