Skip to content

Commit

Permalink
Version 2.0.4 (#16)
Browse files Browse the repository at this point in the history
## Version 2.0.4 - 23.09.2018
- `BacktraceClient` allows developer to unpack `AggregateException` and send only exceptions available in `InnerExceptions` property.
- `BacktraceReport` accepts two new properties: `Factor` and `Fingerprint`. These properties allows you to change server side algorithms. 
- `BacktraceData` now include informations about `Exception` properties. You can check detailed `Exception` properties in Annotations.
- `BacktraceDatabase` doesn't throw exception when developer can't add new record. This situation exists when database was full or database hasn't enough disk space for exceptions.
- `BacktraceResult` can use new `Status`. In case when developer want to unpack `AggregateException` and `InnerExceptions` property is empty, `BacktraceClient` return `BacktraceResult` with status `Empty`,
  • Loading branch information
konraddysput authored Sep 24, 2018
1 parent a5f98ba commit 0d32fac
Show file tree
Hide file tree
Showing 31 changed files with 485 additions and 197 deletions.
6 changes: 0 additions & 6 deletions Backtrace.Tests/Backtrace.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Remove="IntegrationTests\Template.cshtml" />
</ItemGroup>
<ItemGroup>
<Compile Remove="IntegrationTests\Template.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Backtrace\Backtrace.csproj" />
</ItemGroup>
Expand Down
70 changes: 70 additions & 0 deletions Backtrace.Tests/ClientTests/AggregateExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Backtrace.Interfaces;
using Backtrace.Model;
using Backtrace.Types;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace Backtrace.Tests.ClientTests
{
[TestFixture(
Author = "Konrad Dysput",
Category = "Client.AggreagateException",
Description = "Test client bahaviour for handling aggreagate exceptions")]
public class AggregateExceptionTests
{
protected BacktraceClient _backtraceClient;

[SetUp]
public virtual void Setup()
{
var api = new Mock<IBacktraceApi>();
api.Setup(n => n.Send(It.IsAny<BacktraceData>()))
.Returns(new BacktraceResult() { Status = BacktraceResultStatus.Ok });

api.Setup(n => n.SendAsync(It.IsAny<BacktraceData>()))
.ReturnsAsync(() => new BacktraceResult() { Status = BacktraceResultStatus.Ok });

var credentials = new BacktraceCredentials(@"https://validurl.com/", "validToken");
_backtraceClient = new BacktraceClient(credentials)
{
BacktraceApi = api.Object,
UnpackAggregateExcetpion = true
};
}

[Test(Description = "Test empty aggregate exception")]
public void TestEmptyAggreagateException()
{
var aggregateException = new AggregateException("test exception");
var result = _backtraceClient.Send(aggregateException);
Assert.IsNotNull(result);
Assert.AreEqual(result.Status, BacktraceResultStatus.Empty);
}

[Test(Description = "Test default scenario for aggregate exception")]
public void TestAggreagateException()
{
var aggregateException = new AggregateException("test exception",
new List<Exception>() {
new ArgumentException("argument exception"),
new InvalidOperationException("invalid operation exception"),
new FormatException("format exception"),
});
var result = _backtraceClient.Send(aggregateException);

Assert.IsNotNull(result);
Assert.AreEqual(result.Status, BacktraceResultStatus.Ok);

int totalReports = 0;
while (result != null)
{
totalReports++;
result = result.InnerExceptionResult;
}
Assert.AreEqual(3, totalReports);

}
}
}
8 changes: 3 additions & 5 deletions Backtrace.Tests/ClientTests/LogCreationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
using Backtrace.Model;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Tests.ClientTests
{
Expand All @@ -19,7 +15,9 @@ public class LogCreationBase
public virtual void Setup()
{
var api = new Mock<IBacktraceApi>();
api.Setup(n => n.Send(It.IsAny<BacktraceData>())).Returns(new BacktraceResult());
api.Setup(n => n.Send(It.IsAny<BacktraceData>()))
.Returns(new BacktraceResult() { Status = Types.BacktraceResultStatus.Ok });

var credentials = new BacktraceCredentials(@"https://validurl.com/", "validToken");
_backtraceClient = new BacktraceClient(credentials)
{
Expand Down
48 changes: 41 additions & 7 deletions Backtrace.Tests/DatabaseTests/BatchTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Backtrace.Tests.DatabaseTests.Model;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Tests.DatabaseTests
{
Expand All @@ -17,11 +12,12 @@ public class BatchTests : DatabaseTestBase
/// <summary>
/// Add record to first batch on context
/// </summary>
private void AddRecords(int numberOfRecordsOnBatch)
private void AddRecords(int numberOfRecordsOnBatch, bool locked = false)
{
for (int i = 0; i < numberOfRecordsOnBatch; i++)
{
_database.BacktraceDatabaseContext.Add(GetRecord());
var fakeRecord = _database.BacktraceDatabaseContext.Add(GetRecord());
fakeRecord.Locked = locked;
}
}
[TestCase(3, 2, 0)]
Expand Down Expand Up @@ -54,5 +50,43 @@ public void TestBatchAdd(int recordsOnFirstBatch, int recordsOnSecoundBatch, int
totalRecords = _database.BacktraceDatabaseContext.Count();
Assert.AreEqual(totalRecords, recordsOnFirstBatch + recordsOnSecoundBatch);
}

[Test]
public void TestRecordLimitInBatches()
{
_database.Start();
_database.Clear();
//value from database settings
int maxRecordCount = 100;
AddRecords(maxRecordCount);

var report = new Backtrace.Model.BacktraceReport("report");
var result = _database.Add(
backtraceReport: report,
attributes: null,
miniDumpType: Types.MiniDumpType.None
);
Assert.IsNotNull(result);
Assert.AreEqual(maxRecordCount, _database.Count());
}

[Test]
public void TestRecordLimitWithAllReservedBatches()
{
_database.Start();
_database.Clear();
//value from database settings
int maxRecordCount = 100;
AddRecords(maxRecordCount, true);

var report = new Backtrace.Model.BacktraceReport("report");
var result = _database.Add(
backtraceReport: report,
attributes: null,
miniDumpType: Types.MiniDumpType.None
);
Assert.IsNull(result);
Assert.AreEqual(maxRecordCount, _database.Count());
}
}
}
15 changes: 8 additions & 7 deletions Backtrace.Tests/DatabaseTests/DatabaseConditionTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Backtrace.Extensions;
using Backtrace.Interfaces;
using Backtrace.Model;
using Backtrace.Model.Database;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Tests.DatabaseTests
{
Expand All @@ -23,7 +21,7 @@ public class DatabaseConditionTests
/// <summary>
/// Current project directory - any database path
/// </summary>
private readonly string _projectDirectory = Environment.CurrentDirectory;
private readonly string _projectDirectory = System.IO.Path.GetTempPath();

/// <summary>
/// Total number of reports
Expand All @@ -41,7 +39,8 @@ public void Setup()

var backtraceDatabaseSettings = new BacktraceDatabaseSettings(_projectDirectory)
{
MaxRecordCount = _totalNumberOfReports
MaxRecordCount = _totalNumberOfReports,
RetryBehavior = Types.RetryBehavior.NoRetry
};

_backtraceDatabase = new BacktraceDatabase(backtraceDatabaseSettings)
Expand All @@ -59,9 +58,11 @@ public void TestDatabaseRecordLimitConditions()
_backtraceDatabase.Clear();
for (int i = 0; i < _totalNumberOfReports; i++)
{
_backtraceDatabase.Add(backtraceReport, new Dictionary<string, object>(), Types.MiniDumpType.None);
var record = _backtraceDatabase.Add(backtraceReport, new Dictionary<string, object>(), Types.MiniDumpType.None);
record.Dispose();
}
Assert.Throws<ArgumentException>(() => _backtraceDatabase.Add(backtraceReport, new Dictionary<string, object>(),Types.MiniDumpType.None));
_backtraceDatabase.Add(backtraceReport, new Dictionary<string, object>(), Types.MiniDumpType.None);
Assert.AreEqual(_totalNumberOfReports, _backtraceDatabase.Count());
}

[TestCase(1)]
Expand Down
26 changes: 15 additions & 11 deletions Backtrace.Tests/DatabaseTests/DatabaseContextOperationTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using Backtrace.Interfaces;
using Backtrace.Model;
using Backtrace.Model.Database;
using Backtrace.Tests.DatabaseTests.Model;
using Backtrace.Types;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Tests.DatabaseTests
{
Expand Down Expand Up @@ -36,14 +31,23 @@ public void TestMaximumNumberOfRecords()
{
_database.Clear();
//we set maximum number of records to equal to 100 in Setup method on DatabaseTestBase class
int maximumNumberOfRecords = 101;
int maximumNumberOfRecords = 100;
//we add 100 records - 100 is our database limit
for (int i = 0; i < maximumNumberOfRecords - 1; i++)
for (int i = 0; i < maximumNumberOfRecords; i++)
{
_database.BacktraceDatabaseContext.Add(GetRecord());
var fakeRecord = GetRecord();
var record = _database.BacktraceDatabaseContext.Add(fakeRecord);
fakeRecord.Locked = false;
}
_database.Start();
Assert.Throws<ArgumentException>(() => _database.Add(null, new Dictionary<string, object>(), MiniDumpType.None));
_database.Add(
backtraceReport: new BacktraceReport("fake report"),
attributes: new Dictionary<string, object>(),
miniDumpType: MiniDumpType.None);

// in the end BacktraceDatabase should contain 100 reports.
// Database should remove first ever report.
Assert.AreEqual(_database.Count(), maximumNumberOfRecords);
}


Expand Down Expand Up @@ -82,7 +86,7 @@ public void TestFifoListOrder(int totalNumberOfRecords)
{
var record = GetRecord();
records.Add(record);
_database.BacktraceDatabaseContext.Add(record);
var dbRecord = _database.BacktraceDatabaseContext.Add(record);
}
DisposeRecords();
foreach (var record in records)
Expand Down
2 changes: 1 addition & 1 deletion Backtrace.Tests/DatabaseTests/DatabaseSetupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DatabaseSetupTests
/// <summary>
/// Current project directory
/// </summary>
private readonly string _projectDirectory = Environment.CurrentDirectory;
private readonly string _projectDirectory = System.IO.Path.GetTempPath();

[Test(Author = "Konrad Dysput", Description = "Test database initialization")]
public void TestDatabaseInitalizationConditions()
Expand Down
15 changes: 7 additions & 8 deletions Backtrace.Tests/DatabaseTests/Model/DatabaseTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Backtrace.Base;
using Backtrace.Interfaces;
using Backtrace.Interfaces.Database;
using Backtrace.Interfaces;
using Backtrace.Model;
using Backtrace.Model.Database;
using Backtrace.Services;
Expand All @@ -10,9 +8,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Backtrace.Tests.DatabaseTests.Model
{
Expand All @@ -30,7 +25,7 @@ public class DatabaseTestBase
public virtual void Setup()
{
//get project path
string projectPath = Environment.CurrentDirectory;
string projectPath = Path.GetTempPath();

//mock api
var mockApi = new Mock<IBacktraceApi>();
Expand All @@ -49,9 +44,10 @@ public virtual void Setup()

var settings = new BacktraceDatabaseSettings(projectPath)
{
RetryBehavior = RetryBehavior.NoRetry,
AutoSendMode = false, //we don't want to test timers
MaxRecordCount = 100,
RetryLimit = 3
RetryLimit = 3
};
_database = new BacktraceDatabase(settings)
{
Expand Down Expand Up @@ -85,6 +81,9 @@ protected BacktraceDatabaseRecord GetRecord()
mockRecord.Setup(n => n.Delete());
mockRecord.Setup(n => n.BacktraceData)
.Returns(new BacktraceData(It.IsAny<BacktraceReport>(), It.IsAny<Dictionary<string, object>>()));
mockRecord.Setup(n => n.Valid())
.Returns(true);

var data = new BacktraceData(null, new Dictionary<string, object>());
mockRecord.SetupProperty(n => n.Record, data);

Expand Down
Loading

0 comments on commit 0d32fac

Please sign in to comment.