From 2a5eae8b5e4cd844af12daabda7c65f272dd817d Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Tue, 8 Dec 2020 08:16:20 -0600 Subject: [PATCH] #746 - Add more test coverage for resolving new stack counts --- .../Models/StackSummaryModel.cs | 2 + .../Controllers/EventControllerTests.cs | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/src/Exceptionless.Core/Models/StackSummaryModel.cs b/src/Exceptionless.Core/Models/StackSummaryModel.cs index d7afd0dd26..06f2716ebf 100644 --- a/src/Exceptionless.Core/Models/StackSummaryModel.cs +++ b/src/Exceptionless.Core/Models/StackSummaryModel.cs @@ -1,6 +1,8 @@ using System; +using System.Diagnostics; namespace Exceptionless.Core.Models { + [DebuggerDisplay("Id: {Id}, Status: {Status}, Title: {Title}, First: {FirstOccurrence}, Last: {LastOccurrence}")] public class StackSummaryModel : SummaryData { public string Id { get; set; } public string Title { get; set; } diff --git a/tests/Exceptionless.Tests/Controllers/EventControllerTests.cs b/tests/Exceptionless.Tests/Controllers/EventControllerTests.cs index 97a187e63c..fd497257bb 100644 --- a/tests/Exceptionless.Tests/Controllers/EventControllerTests.cs +++ b/tests/Exceptionless.Tests/Controllers/EventControllerTests.cs @@ -534,6 +534,102 @@ await CreateDataAsync(d => { Assert.Equal(1, uniqueTotal); } + [Fact] + public async Task WillExcludeOldStacksForStackNewMode() { + var utcNow = SystemClock.UtcNow; + + await CreateDataAsync(d => { + d.Event() + .TestProject() + .Message("New stack - skip due to date filter") + .Type(Event.KnownTypes.Log) + .Status(StackStatus.Open) + .TotalOccurrences(50) + .IsFirstOccurrence() + .FirstOccurrence(utcNow.SubtractYears(1)) + .LastOccurrence(utcNow.SubtractMonths(5)); + + d.Event() + .TestProject() + .Message("Old stack - new event") + .Type(Event.KnownTypes.Log) + .Status(StackStatus.Regressed) + .TotalOccurrences(33) + .FirstOccurrence(utcNow.SubtractYears(1)) + .LastOccurrence(utcNow); + + d.Event() + .TestProject() + .Message("New Stack - event not marked as first occurrence") + .Type(Event.KnownTypes.Log) + .Status(StackStatus.Open) + .TotalOccurrences(15) + .FirstOccurrence(utcNow.SubtractDays(2)) + .Version("1.2.3"); + + d.Event() + .TestProject() + .Message("New Stack - event marked as first occurrence") + .Type(Event.KnownTypes.Error) + .Status(StackStatus.Regressed) + .TotalOccurrences(10) + .FirstOccurrence(utcNow.SubtractDays(2)) + .Date(utcNow.SubtractDays(2)) + .IsFirstOccurrence() + .StackReference("https://github.com/exceptionless/Exceptionless") + .Version("3.2.1-beta1"); + + d.Event() + .TestProject() + .Message("Deleted New stack - event is first occurrence") + .Type(Event.KnownTypes.FeatureUsage) + .Status(StackStatus.Open) + .TotalOccurrences(7) + .FirstOccurrence(utcNow.Date) + .IsFirstOccurrence() + .Date(utcNow.Date) + .Deleted(); + }); + + Log.SetLogLevel(LogLevel.Trace); + Log.SetLogLevel(LogLevel.Trace); + const string filter = "(status:open OR status:regressed)"; + const string time = "last week"; + var results = await SendRequestAsAsync>(r => r + .AsGlobalAdminUser() + .AppendPath("events") + .QueryString("filter", filter) + .QueryString("time", time) + .QueryString("mode", "stack_new") + .StatusCodeShouldBeOk() + ); + + Assert.Equal(2, results.Count); + + var countResult = await SendRequestAsAsync(r => r + .AsGlobalAdminUser() + .AppendPath("events", "count") + .QueryString("filter", filter) + .QueryString("time", time) + .QueryString("aggregations", "date:(date cardinality:stack sum:count~1) cardinality:stack terms:(first @include:true) sum:count~1") + .StatusCodeShouldBeOk() + ); + + var dateAgg = countResult.Aggregations.DateHistogram("date_date"); + double dateAggStackCount = dateAgg.Buckets.Sum(t => t.Aggregations.Cardinality("cardinality_stack").Value.GetValueOrDefault()); + double dateAggEventCount = dateAgg.Buckets.Sum(t => t.Aggregations.Cardinality("sum_count").Value.GetValueOrDefault()); + Assert.Equal(1, dateAggStackCount); + Assert.Equal(1, dateAggEventCount); + + var total = countResult.Aggregations.Sum("sum_count")?.Value; + double newTotal = countResult.Aggregations.Terms("terms_first")?.Buckets.FirstOrDefault()?.Total ?? 0; + double uniqueTotal = countResult.Aggregations.Cardinality("cardinality_stack")?.Value ?? 0; + + Assert.Equal(1, total); + Assert.Equal(0, newTotal); + Assert.Equal(1, uniqueTotal); + } + private async Task CreateStacksAndEventsAsync() { var utcNow = SystemClock.UtcNow;