|  | 
|  | 1 | +using Hangfire; | 
|  | 2 | +using Hangfire.Common; | 
|  | 3 | +using Hangfire.Server; | 
|  | 4 | +using Hangfire.Storage; | 
|  | 5 | + | 
|  | 6 | +namespace Sentry.Hangfire.Tests; | 
|  | 7 | + | 
|  | 8 | +public class ServerFilterTests | 
|  | 9 | +{ | 
|  | 10 | +    [Fact] | 
|  | 11 | +    public void OnPerforming_IsReentrant() | 
|  | 12 | +    { | 
|  | 13 | +        // Arrange | 
|  | 14 | +        const string jobId = "test-id"; | 
|  | 15 | +        const string monitorSlug = "test-monitor-slug"; | 
|  | 16 | + | 
|  | 17 | +        var storageConnection = Substitute.For<IStorageConnection>(); | 
|  | 18 | +        storageConnection.GetJobParameter(jobId, SentryServerFilter.SentryMonitorSlugKey).Returns( | 
|  | 19 | +            SerializationHelper.Serialize(monitorSlug) | 
|  | 20 | +            ); | 
|  | 21 | + | 
|  | 22 | +        var backgroundJob = new BackgroundJob(jobId, null, DateTime.Now); | 
|  | 23 | +        var cancellationToken = Substitute.For<IJobCancellationToken>(); | 
|  | 24 | +        var performContext = new PerformContext( | 
|  | 25 | +            null, | 
|  | 26 | +            storageConnection, | 
|  | 27 | +            backgroundJob, | 
|  | 28 | +            cancellationToken | 
|  | 29 | +            ); | 
|  | 30 | +        var performingContext = new PerformingContext(performContext); | 
|  | 31 | + | 
|  | 32 | +        var hub = Substitute.For<IHub>(); | 
|  | 33 | +        hub.CaptureCheckIn(monitorSlug, CheckInStatus.InProgress).Returns(SentryId.Create()); | 
|  | 34 | + | 
|  | 35 | +        var logger = Substitute.For<IDiagnosticLogger>(); | 
|  | 36 | +        var filter = new SentryServerFilter(hub, logger); | 
|  | 37 | + | 
|  | 38 | +        // Act | 
|  | 39 | +        filter.OnPerforming(performingContext); | 
|  | 40 | + | 
|  | 41 | +        // Assert | 
|  | 42 | +        performContext.Items.ContainsKey(SentryServerFilter.SentryCheckInIdKey).Should().BeTrue(); | 
|  | 43 | +        var firstKey = performingContext.Items[SentryServerFilter.SentryCheckInIdKey]; | 
|  | 44 | + | 
|  | 45 | +        // Act | 
|  | 46 | +        filter.OnPerforming(performingContext); | 
|  | 47 | + | 
|  | 48 | +        // Assert | 
|  | 49 | +        performContext.Items.ContainsKey(SentryServerFilter.SentryCheckInIdKey).Should().BeTrue(); | 
|  | 50 | +        performingContext.Items[SentryServerFilter.SentryCheckInIdKey].Should().NotBeSameAs(firstKey); | 
|  | 51 | +    } | 
|  | 52 | +} | 
0 commit comments