Skip to content

Commit

Permalink
Improve performance by changing ActionNotification to be a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Galad committed Aug 8, 2020
1 parent c5a4b31 commit 1592b71
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Tranquire/Reporting/ActionNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represent informations about the action execution
/// </summary>
public class ActionNotification
public struct ActionNotification
{
/// <summary>
/// The action that trigerred the notification
Expand Down
9 changes: 2 additions & 7 deletions src/Tranquire/Reporting/RenderedReportingObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public void OnError(Exception error)
/// <inheritsdoc />
public void OnNext(ActionNotification value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

Observer.OnNext(Renderer(value));
}

Expand All @@ -67,9 +62,9 @@ public void OnNext(ActionNotification value)
/// <returns></returns>
public static string DefaultRenderer(ActionNotification notification)
{
if (notification == null)
if (notification.Content == null)
{
throw new ArgumentNullException(nameof(notification));
return "Unknown action";
}

switch (notification.Content.NotificationContentType)
Expand Down
4 changes: 2 additions & 2 deletions src/Tranquire/Reporting/XmlDocumentObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public void OnError(Exception error)
/// <inheritsdoc />
public void OnNext(ActionNotification value)
{
if (value == null)
if (value.Content == null)
{
throw new ArgumentNullException(nameof(value));
return;
}

switch (value.Content.NotificationContentType)
Expand Down
14 changes: 7 additions & 7 deletions tests/Tranquire.Tests/Reporting/ReportingActorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void Sut_AllMethods_ShouldCallOnNext(
new ActionNotification(action, 1, new BeforeActionNotificationContent(date, commandType)),
new ActionNotification(action, 1, new AfterActionNotificationContent(expectedDuration))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

[Theory, MemberData(nameof(NotifyingTestCases))]
Expand Down Expand Up @@ -250,7 +250,7 @@ BeforeActionNotificationContent before()
new ActionNotification(actions[1], 2, new AfterActionNotificationContent(expectedDurations[1])),
new ActionNotification(actions[0], 1, new AfterActionNotificationContent(expectedDurations[0]))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

[Theory, MemberData(nameof(ExecutionTestCases))]
Expand Down Expand Up @@ -305,7 +305,7 @@ public void Sut_AllMethods_WhenErrorOccurs_ShouldCallOnNext(
new ActionNotification(action, 1, new BeforeActionNotificationContent(date, commandType)),
new ActionNotification(action, 1, new ExecutionErrorNotificationContent(exception, expectedDuration))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

[Theory, MemberData(nameof(NotifyingTestCases))]
Expand Down Expand Up @@ -364,7 +364,7 @@ BeforeActionNotificationContent before()
new ActionNotification(actions[1], 2, new ExecutionErrorNotificationContent(exception, expectedDuration)),
new ActionNotification(actions[0], 1, new ExecutionErrorNotificationContent(exception, expectedDuration))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

[Theory, ReportingActorAutoData]
Expand Down Expand Up @@ -446,7 +446,7 @@ ThenAction<object, string> thenAction
new ActionNotification(thenAction, 1, new BeforeThenNotificationContent(date, thenAction.Question)),
new ActionNotification(thenAction, 1, new AfterThenNotificationContent(expectedDuration, ThenOutcome.Pass))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

[Theory, ReportingActorAutoData]
Expand Down Expand Up @@ -476,7 +476,7 @@ TimeSpan expectedDuration
new ActionNotification(thenAction, 1, new BeforeThenNotificationContent(date, thenAction.Question)),
new ActionNotification(thenAction, 1, new AfterThenNotificationContent(expectedDuration, ThenOutcome.Error, error))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}

private static System.Action[] _assertions = new System.Action[]
Expand Down Expand Up @@ -531,7 +531,7 @@ TimeSpan expectedDuration
new ActionNotification(thenAction, 1, new BeforeThenNotificationContent(date, thenAction.Question)),
new ActionNotification(thenAction, 1, new AfterThenNotificationContent(expectedDuration, ThenOutcome.Failed, expectedException))
};
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes());
observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers<ActionNotification>());
}
}
}
6 changes: 4 additions & 2 deletions tests/Tranquire.Tests/Reporting/XmlDocumentObserverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ XmlReportItem createItem(
(notifications, a) => notifications
.Insert(0, new ActionNotification(a.action, a.i + 1, new BeforeActionNotificationContent(DateTimeOffset.MinValue, a.commandType)))
.Add(new ActionNotification(a.action, a.i + 1, new AfterActionNotificationContent(TimeSpan.FromSeconds(a.i))))
),
)
.ToArray(),
actions.Select((a,i) => (a.action, a.commandType, i))
.Select(a => createItem(a.commandType, a.action.Name, DateTimeOffset.MinValue, a.i * 1000))
.Reverse()
Expand Down Expand Up @@ -260,7 +261,8 @@ XmlReportItem createItem(
.Add(new ActionNotification(a.action, a.i + 1,
new ExecutionErrorNotificationContent(a.exception, TimeSpan.FromSeconds(a.i))
))
),
)
.ToArray(),
actions.Select((a,i) => (a.action, a.commandType, exception, i))
.Select(a =>
createItem(
Expand Down
1 change: 0 additions & 1 deletion tests/Tranquire.Tests/ThenActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public void Sut_ConstructorInitializedMember(ConstructorInitializedMemberAsserti
{
assertion.Verify<ThenAction<object, string>>(a => new object[]
{
a.Question,
a.VerifyAction
});
}
Expand Down

0 comments on commit 1592b71

Please sign in to comment.