Skip to content

Commit

Permalink
[repo/Hangfire] Prepare to .NET9 (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Nov 5, 2024
1 parent 09e3619 commit cca539c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static void InjectActivityProperties(IDictionary<string, string> jobPara

private static IEnumerable<string> ExtractActivityProperties(Dictionary<string, string> telemetryData, string key)
{
return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty<string>();
return telemetryData.TryGetValue(key, out var value) ? [value] : [];
}

private void SetStatusAndRecordException(Activity activity, Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

namespace OpenTelemetry.Instrumentation.Hangfire.Tests;

#pragma warning disable CA1515
public class HangfireFixture : IDisposable
#pragma warning restore CA1515
{
public HangfireFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public async Task Should_Create_Activity()
await this.WaitJobProcessedAsync(jobId, 5);

// Assert
Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId);
var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId);
Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId);
var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId);
Assert.Contains("JOB TestJob.Execute", activity.DisplayName);
Assert.Equal(ActivityKind.Internal, activity.Kind);
}
Expand All @@ -55,8 +55,8 @@ public async Task Should_Create_Activity_With_Status_Error_When_Job_Failed()
await this.WaitJobProcessedAsync(jobId, 5);

// Assert
Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId);
var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId);
Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId);
var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId);
Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName);
Assert.Equal(ActivityKind.Internal, activity.Kind);
Assert.Equal(ActivityStatusCode.Error, activity.Status);
Expand All @@ -79,8 +79,8 @@ public async Task Should_Create_Activity_With_Exception_Event_When_Job_Failed_An
await this.WaitJobProcessedAsync(jobId, 5);

// Assert
Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId);
var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId);
Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId);
var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId);
Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName);
Assert.Equal(ActivityKind.Internal, activity.Kind);
Assert.Equal(ActivityStatusCode.Error, activity.Status);
Expand All @@ -103,8 +103,8 @@ public async Task Should_Create_Activity_Without_Exception_Event_When_Job_Failed
await this.WaitJobProcessedAsync(jobId, 5);

// Assert
Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId);
var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId);
Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId);
var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId);
Assert.Contains("JOB TestJob.ThrowException", activity.DisplayName);
Assert.Equal(ActivityKind.Internal, activity.Kind);
Assert.Equal(ActivityStatusCode.Error, activity.Status);
Expand All @@ -128,8 +128,8 @@ public async Task Should_Create_Activity_With_Custom_DisplayName()
await this.WaitJobProcessedAsync(jobId, 5);

// Assert
Assert.Single(exportedItems, i => i.GetTagItem("job.id") as string == jobId);
var activity = exportedItems.Single(i => i.GetTagItem("job.id") as string == jobId);
Assert.Single(exportedItems, i => (i.GetTagItem("job.id") as string) == jobId);
var activity = exportedItems.Single(i => (i.GetTagItem("job.id") as string) == jobId);
Assert.Contains($"JOB {jobId}", activity.DisplayName);
Assert.Equal(ActivityKind.Internal, activity.Kind);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task Should_Respect_Filter_Option(string filter, bool shouldRecord)
private async Task WaitJobProcessedAsync(string jobId, int timeToWaitInSeconds)
{
var timeout = DateTime.Now.AddSeconds(timeToWaitInSeconds);
string[] states = new[] { "Enqueued", "Processing" };
string[] states = ["Enqueued", "Processing"];
JobDetailsDto jobDetails;
while (((jobDetails = this.hangfireFixture.MonitoringApi.JobDetails(jobId)) == null || jobDetails.History.All(h => states.Contains(h.StateName)))
&& DateTime.Now < timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenTelemetry.Instrumentation.Hangfire.Tests;

public class ProcessorMock<T> : BaseProcessor<T>
internal class ProcessorMock<T> : BaseProcessor<T>
{
private readonly Action<T>? onStart;
private readonly Action<T>? onEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenTelemetry.Instrumentation.Hangfire.Tests;

public class TestJob
internal class TestJob
{
public void Execute()
{
Expand Down

0 comments on commit cca539c

Please sign in to comment.