Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jun 9, 2022
1 parent a36bc8d commit 5905cd7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
clientReportJson: {
discarded_events: [
{
category: internal,
quantity: 1,
reason: network_error
},
{
category: security,
quantity: 1,
reason: network_error
},
{
category: error,
quantity: 2,
reason: queue_overflow
},
{
category: transaction,
quantity: 3,
reason: ratelimit_backoff
}
],
timestamp: Date_MaxValue
},
eventItemJson: {
event_id: Guid_1,
platform: csharp,
sdk: {},
sent_at: DateTime_1,
timestamp: DateTime_2
}
}
20 changes: 4 additions & 16 deletions test/Sentry.Tests/Internals/Http/HttpTransportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Sentry.Tests.Internals.Http;

[UsesVerify]
public class HttpTransportTests
{
[Fact]
Expand Down Expand Up @@ -769,7 +770,7 @@ public async Task CreateRequest_Content_IncludesEvent()
}

[Fact]
public void ProcessEnvelope_ShouldAttachClientReport()
public Task ProcessEnvelope_ShouldAttachClientReport()
{
var options = new SentryOptions();

Expand All @@ -794,7 +795,6 @@ public void ProcessEnvelope_ShouldAttachClientReport()
recorder.RecordDiscardedEvent(DiscardReason.RateLimitBackoff, DataCategory.Transaction);

var sentryEvent = new SentryEvent();
var expectedEventJson = EnvelopeItem.FromEvent(sentryEvent).Payload.SerializeToString(logger);

var envelope = Envelope.FromEvent(sentryEvent);
var processedEnvelope = httpTransport.ProcessEnvelope(envelope);
Expand All @@ -808,21 +808,9 @@ public void ProcessEnvelope_ShouldAttachClientReport()
Assert.Equal("event", eventItem.TryGetType());
Assert.Equal("client_report", clientReportItem.TryGetType());

// The event should be unmodified
Assert.Equal(expectedEventJson, eventItem.Payload.SerializeToString(logger));

// The client report should contain the counts of the fake discards
const string expectedClientReportJson =
"{\"timestamp\":\"9999-12-31T23:59:59.9999999+00:00\"," +
"\"discarded_events\":[" +
"{\"reason\":\"network_error\",\"category\":\"internal\",\"quantity\":1}," +
"{\"reason\":\"network_error\",\"category\":\"security\",\"quantity\":1}," +
"{\"reason\":\"queue_overflow\",\"category\":\"error\",\"quantity\":2}," +
"{\"reason\":\"ratelimit_backoff\",\"category\":\"transaction\",\"quantity\":3}" +
"]}";

var eventItemJson = eventItem.Payload.SerializeToString(logger);
var clientReportJson = clientReportItem.Payload.SerializeToString(logger);
Assert.Equal(expectedClientReportJson, clientReportJson);
return VerifyJson($"{{eventItemJson:{eventItemJson},clientReportJson:{clientReportJson}}}");
}

[Fact]
Expand Down

0 comments on commit 5905cd7

Please sign in to comment.