Skip to content

Commit 3ecfa06

Browse files
committed
Established basic load test for TopicMappingService
We should establish more sophisticated load testing. In the meanwhile, this unit test helps provide basic load testing of mapping calls by configuring a number of variables, such as the number of runs, whether or not a comprehensive attribute set should be used, and whether nested topics should be included. This allows optimizations to the code base to be quickly evaluated. This test always passes; the goal is to measure the time it takes. It defaults to 0 runs so it doesn't slow down normal unit test operations.
1 parent afd6c87 commit 3ecfa06

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,87 @@ public TopicMappingServiceTest(TopicInfrastructureFixture<StubTopicRepository> f
6464

6565
}
6666

67+
/*==========================================================================================================================
68+
| TEST: MAP: LOAD TESTING: EVALUATE TIME
69+
\-------------------------------------------------------------------------------------------------------------------------*/
70+
/// <summary>
71+
/// Establishes a <see cref="TopicMappingService"/> and tests creating and mapping <see cref="Topic"/> instances in bulk,
72+
/// as a quick-and-easy way of assessing performance.
73+
/// </summary>
74+
[Fact]
75+
public async Task Map_LoadTesting_EvaluateTime() {
76+
77+
/*------------------------------------------------------------------------------------------------------------------------
78+
| Establish variables
79+
\-----------------------------------------------------------------------------------------------------------------------*/
80+
var runs = 0; // The number of mapping operations to perform
81+
var useFullAttributeSet = false; // Include a larget set of attribute values
82+
var includeNestedTopics = false; // Only include a minimal set of properties
83+
84+
/*------------------------------------------------------------------------------------------------------------------------
85+
| Establish object model
86+
\-----------------------------------------------------------------------------------------------------------------------*/
87+
var currentId = 1;
88+
var baseTopic = new Topic("Base", "Page", null, currentId++);
89+
var grandparent = new Topic("Grandparent", "Page", null, currentId++);
90+
var parent = new Topic("Parent", "Page", grandparent, currentId++);
91+
var topic = new Topic("Test", "ContentList", parent, currentId++);
92+
var contentItems = new Topic("ContentItems", "List", topic, currentId++);
93+
94+
if (includeNestedTopics) {
95+
_ = new Topic("Item1", "ContentItem", contentItems, currentId++);
96+
_ = new Topic("Item2", "ContentItem", contentItems, currentId++);
97+
_ = new Topic("Item3", "ContentItem", contentItems, currentId++);
98+
_ = new Topic("Item4", "ContentItem", contentItems, currentId++);
99+
_ = new Topic("Item5", "ContentItem", contentItems, currentId++);
100+
_ = new Topic("Item6", "ContentItem", contentItems, currentId++);
101+
}
102+
103+
grandparent.BaseTopic = baseTopic;
104+
105+
/*------------------------------------------------------------------------------------------------------------------------
106+
| Populate attributes
107+
\-----------------------------------------------------------------------------------------------------------------------*/
108+
foreach (var contentItem in contentItems.Children) {
109+
contentItem.Attributes.SetDateTime("LastModified", DateTime.Now);
110+
contentItem.Attributes.SetValue("Description", "Value1");
111+
if (useFullAttributeSet) {
112+
contentItem.Attributes.SetValue("LearnMoreUrl", "/Topic/23/");
113+
contentItem.Attributes.SetValue("ThumbnailImage", "/Image.jpg");
114+
contentItem.Attributes.SetValue("Description", "Value1");
115+
contentItem.Attributes.SetValue("Category", "Gumby");
116+
}
117+
}
118+
119+
topic.Attributes.SetValue("Title", "Friendly Title");
120+
topic.Attributes.SetValue("IsHidden", "0");
121+
if (useFullAttributeSet) {
122+
topic.Attributes.SetValue("View", "Test");
123+
topic.Attributes.SetValue("ShortTitle", "Short Title");
124+
topic.Attributes.SetValue("Subtitle", "Subtitle");
125+
topic.Attributes.SetValue("MetaTitle", "Meta Title");
126+
topic.Attributes.SetValue("MetaDescription", "Meta Description");
127+
topic.Attributes.SetValue("MetaKeywords", "Load;Test;Keywords");
128+
topic.Attributes.SetValue("NoIndex", "0");
129+
topic.Attributes.SetValue("Body", "Body of test topic");
130+
}
131+
132+
baseTopic.Attributes.SetValue("Title", "Inherited Title");
133+
134+
/*------------------------------------------------------------------------------------------------------------------------
135+
| Run load testing
136+
\-----------------------------------------------------------------------------------------------------------------------*/
137+
for (var i = 0; i <= runs; i++) {
138+
await _mappingService.MapAsync(topic).ConfigureAwait(false);
139+
}
140+
141+
/*------------------------------------------------------------------------------------------------------------------------
142+
| Always assume the test passed
143+
\-----------------------------------------------------------------------------------------------------------------------*/
144+
Assert.True(true);
145+
146+
}
147+
67148
/*==========================================================================================================================
68149
| TEST: MAP: GENERIC: RETURNS NEW MODEL
69150
\-------------------------------------------------------------------------------------------------------------------------*/
@@ -1444,6 +1525,7 @@ public async Task Map_FlattenAttribute_ExcludeTopics() {
14441525
Assert.Single(target?.Children);
14451526

14461527
}
1528+
14471529
/*==========================================================================================================================
14481530
| TEST: MAP: CACHED TOPIC: RETURNS CACHED MODEL
14491531
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)