test coverage: DependencyCollector and EventCounterCollector and PerformanceCollector (#2381)
* test coverage: DependencyCollector and EventCounterCollector and PerformanceCollector * remove Clear()
This commit is contained in:
Родитель
543ba4d040
Коммит
f576d9f47b
|
@ -3,11 +3,9 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<!-- TargetFrameworks are defined in Test.props, but can be overridden here if needed. -->
|
||||
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
|
||||
<TargetFrameworks>net452;$(TargetFrameworks)</TargetFrameworks>
|
||||
<AssemblyName>Microsoft.ApplicationInsights.DependencyCollector.Tests</AssemblyName>
|
||||
<PackageId>Microsoft.AI.DependencyCollector.Tests</PackageId>
|
||||
|
||||
<NoWarn>1701;1702;1705;1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -26,14 +24,14 @@
|
|||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net5.0' ">
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
|
||||
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' ">
|
||||
<PackageReference Include="System.Buffers" Version="4.5.1" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
|
|
|
@ -465,10 +465,6 @@
|
|||
|
||||
if (request != null)
|
||||
{
|
||||
#if DEBUG
|
||||
var requestIdHeader = request.Headers.GetValues(RequestResponseHeaders.RequestIdHeader).Single();
|
||||
#endif
|
||||
|
||||
if (expectW3CHeaders)
|
||||
{
|
||||
var traceId = item.Context.Operation.Id;
|
||||
|
@ -482,22 +478,21 @@
|
|||
Assert.AreEqual(parentActivity.TraceStateString, request.Headers.GetValues(W3C.W3CConstants.TraceStateHeader).Single());
|
||||
}
|
||||
|
||||
|
||||
#if !NETCOREAPP3_1_OR_GREATER
|
||||
// TODO: THIS IS A TESTING GAP
|
||||
// It appears that .NET CORE 3 does not inject a Request-Id header.
|
||||
var actualRequestIdHeader = request.Headers.GetValues(RequestResponseHeaders.RequestIdHeader).Single();
|
||||
|
||||
if (expectRequestId)
|
||||
{
|
||||
Assert.AreEqual(expectedRequestId, request.Headers.GetValues(RequestResponseHeaders.RequestIdHeader).Single());
|
||||
Assert.AreEqual(expectedRequestId, actualRequestIdHeader);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: THIS IS A TESTING GAP
|
||||
#if NETCOREAPP2_1
|
||||
// even though we don't inject back-compatible request-id, .NET Core 2.0 will inject one that will look like traceparent
|
||||
Assert.AreEqual(expectedTraceParentHeader, request.Headers.GetValues(RequestResponseHeaders.RequestIdHeader).Single());
|
||||
#elif NETCOREAPP3_1
|
||||
// It appears that .NET CORE 3 does not inject a Request-Id header. Need to verify with Liudmila.
|
||||
#else
|
||||
#error This condition is unexpected
|
||||
#endif
|
||||
Assert.AreEqual(expectedTraceParentHeader, actualRequestIdHeader);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -585,4 +580,4 @@
|
|||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,10 +94,6 @@ namespace EventCounterCollector.Tests
|
|||
// VALIDATE
|
||||
ValidateTelemetry(itemsReceived, expectedName, expectedMetricNamespace, expectedMetricValue, expectedMetricCount);
|
||||
|
||||
// Clear the items.
|
||||
Trace.WriteLine("Clearing items received.");
|
||||
itemsReceived.Clear();
|
||||
|
||||
// Wait another refresh interval to receive more events, but with zero as counter values.
|
||||
// as nobody is publishing events.
|
||||
Task.Delay(((int)refreshTimeInSecs * 1000)).Wait();
|
||||
|
@ -144,11 +140,15 @@ namespace EventCounterCollector.Tests
|
|||
double sum = 0.0;
|
||||
int count = 0;
|
||||
|
||||
foreach(var telemetry in metricTelemetries)
|
||||
while (metricTelemetries.TryDequeue(out ITelemetry telemetry))
|
||||
{
|
||||
var metricTelemetry = telemetry as MetricTelemetry;
|
||||
count = count + metricTelemetry.Count.Value;
|
||||
sum = sum + metricTelemetry.Sum;
|
||||
|
||||
if (!double.IsNaN(metricTelemetry.Sum)) // TODO: WHY IS SUM NaN ?
|
||||
{
|
||||
sum += metricTelemetry.Sum;
|
||||
}
|
||||
|
||||
Assert.IsTrue(metricTelemetry.Context.GetInternalContext().SdkVersion.StartsWith("evtc"));
|
||||
Assert.AreEqual(expectedName, metricTelemetry.Name);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<!-- TargetFrameworks are defined in Test.props, but can be overridden here if needed. -->
|
||||
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
|
||||
<AssemblyName>Microsoft.AI.EventCounterCollector.Tests</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -11,6 +10,8 @@
|
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
|
||||
|
||||
<PackageReference Include="System.Diagnostics.Tracing" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<!-- TargetFrameworks are defined in Test.props, but can be overridden here if needed. -->
|
||||
<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>
|
||||
<!--<TargetFrameworks>net452;netcoreapp3.1</TargetFrameworks>-->
|
||||
<TargetFrameworks>net452;$(TargetFrameworks)</TargetFrameworks>
|
||||
<AssemblyName>Microsoft.AI.PerformanceCollector.Tests</AssemblyName>
|
||||
<RootNamespace>Microsoft.ApplicationInsights.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
@ -22,7 +23,7 @@
|
|||
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'net480' ">
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
[TestClass]
|
||||
public class PerformanceCollectorModulesTests
|
||||
{
|
||||
#if NET452
|
||||
#if NETFRAMEWORK
|
||||
[TestMethod]
|
||||
[SuppressMessage(category: "Microsoft.Globalization", checkId: "CA1305:SpecifyIFormatProvider", Justification = "Don't care about invariant in unit tests.")]
|
||||
public void TimerTest()
|
||||
|
@ -434,7 +434,7 @@
|
|||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\Memory\Available Bytes"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\Process(??APP_WIN32_PROC??)\IO Data Bytes/sec"));
|
||||
|
||||
#if NET452
|
||||
#if NETFRAMEWORK
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\.NET CLR Exceptions(??APP_CLR_PROC??)\# of Exceps Thrown / sec"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time"));
|
||||
|
@ -473,7 +473,7 @@
|
|||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\Memory\Available Bytes"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\Process(??APP_WIN32_PROC??)\IO Data Bytes/sec"));
|
||||
|
||||
#if NET452
|
||||
#if NETFRAMEWORK
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\.NET CLR Exceptions(??APP_CLR_PROC??)\# of Exceps Thrown / sec"));
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time"));
|
||||
|
@ -481,7 +481,7 @@
|
|||
#endif
|
||||
|
||||
Assert.IsTrue(ContainsPerfCounter(module.DefaultCounters, @"\Processor(_Total)\% Processor Time"));
|
||||
#if NET452
|
||||
#if NETFRAMEWORK
|
||||
Assert.AreEqual(10, module.DefaultCounters.Count);
|
||||
#else
|
||||
Assert.AreEqual(6, module.DefaultCounters.Count);
|
||||
|
|
Загрузка…
Ссылка в новой задаче