-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathMsTestV2Tests.cs
More file actions
288 lines (234 loc) · 15.4 KB
/
MsTestV2Tests.cs
File metadata and controls
288 lines (234 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// <copyright file="MsTestV2Tests.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Datadog.Trace.Ci.Tags;
using Datadog.Trace.Configuration;
using Datadog.Trace.ExtensionMethods;
using Datadog.Trace.TestHelpers;
using FluentAssertions;
using VerifyXunit;
using Xunit;
using Xunit.Abstractions;
#pragma warning disable SA1402
namespace Datadog.Trace.ClrProfiler.IntegrationTests.CI
{
public class MsTestV2Tests(ITestOutputHelper output) : MsTestV2TestsBase("MSTestTests", output, pre224TestCount: 20, post224TestCount: 22);
public class MsTestV2Tests2(ITestOutputHelper output) : MsTestV2TestsBase("MSTestTests2", output, pre224TestCount: 19, post224TestCount: 21);
[Collection("MsTestV2Tests")]
[UsesVerify]
public abstract class MsTestV2TestsBase : TestingFrameworkTest
{
private readonly GacFixture _gacFixture;
public MsTestV2TestsBase(string sampleAppName, ITestOutputHelper output, int pre224TestCount, int post224TestCount)
: base(sampleAppName, output)
{
TestBundleName = $"Samples.{sampleAppName}";
TestSuiteName = "Samples.MSTestTests.TestSuite";
ClassInitializationExceptionTestSuiteName = "Samples.MSTestTests.ClassInitializeExceptionTestSuite";
Pre224TestCount = pre224TestCount;
Post224TestCount = post224TestCount;
SetServiceName("mstest-tests");
SetServiceVersion("1.0.0");
_gacFixture = new GacFixture();
_gacFixture.AddAssembliesToGac();
}
protected virtual string TestSuiteName { get; }
protected virtual string TestBundleName { get; }
protected virtual string ClassInitializationExceptionTestSuiteName { get; }
protected virtual int Pre224TestCount { get; }
protected virtual int Post224TestCount { get; }
public override void Dispose()
{
_gacFixture.RemoveAssembliesFromGac();
}
[SkippableTheory]
[MemberData(nameof(PackageVersions.MSTest), MemberType = typeof(PackageVersions))]
[Trait("Category", "EndToEnd")]
[Trait("Category", "TestIntegrations")]
public async Task SubmitTraces(string packageVersion)
{
var version = string.IsNullOrEmpty(packageVersion) ? new Version("2.2.8") : new Version(packageVersion);
List<MockSpan> spans = null;
var expectedSpanCount = version.CompareTo(new Version("2.2.3")) <= 0 ? Pre224TestCount : Post224TestCount;
try
{
SetEnvironmentVariable(ConfigurationKeys.CIVisibility.Enabled, "1");
using (var agent = EnvironmentHelper.GetMockAgent())
{
// We remove the evp_proxy endpoint to force the APM protocol compatibility
agent.Configuration.Endpoints = agent.Configuration.Endpoints.Where(e => !e.Contains("evp_proxy/v2") && !e.Contains("evp_proxy/v4")).ToArray();
using (ProcessResult processResult = await RunDotnetTestSampleAndWaitForExit(agent, packageVersion: packageVersion, expectedExitCode: 1))
{
spans = (await agent.WaitForSpansAsync(expectedSpanCount))
.Where(s => !(s.Tags.TryGetValue(Tags.InstrumentationName, out var sValue) && sValue == "HttpMessageHandler"))
.ToList();
var settings = VerifyHelper.GetCIVisibilitySpanVerifierSettings(expectedSpanCount == Pre224TestCount ? "pre_2_2_4" : "post_2_2_4");
settings.DisableRequireUniquePrefix();
await Verifier.Verify(spans.OrderBy(s => s.Resource).ThenBy(s => s.Tags.GetValueOrDefault(TestTags.Name)).ThenBy(s => s.Tags.GetValueOrDefault(TestTags.Parameters)), settings);
// Check the span count
Assert.Equal(expectedSpanCount, spans.Count);
foreach (var targetSpan in spans)
{
// Remove decision maker tag (not used by the backend for civisibility)
targetSpan.Tags.Remove(Tags.Propagated.DecisionMaker);
targetSpan.Tags.Remove(Tags.Propagated.TraceIdUpper);
// Remove git metadata added by the apm agent writer.
targetSpan.Tags.Remove(Tags.GitCommitSha);
targetSpan.Tags.Remove(Tags.GitRepositoryUrl);
// Remove EFD tags
targetSpan.Tags.Remove(TestTags.TestIsNew);
targetSpan.Tags.Remove(TestTags.TestIsRetry);
// Remove test final status
targetSpan.Tags.Remove(TestTags.TestFinalStatus);
// Remove capabilities
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesAutoTestRetries);
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesTestManagementQuarantine);
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesEarlyFlakeDetection);
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesTestImpactAnalysis);
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesTestManagementDisable);
targetSpan.Tags.Remove(CapabilitiesTags.LibraryCapabilitiesTestManagementAttemptToFix);
// Remove user provided service tag
targetSpan.Tags.Remove(CommonTags.UserProvidedTestServiceTag);
// check the name
Assert.Equal("mstestv2.test", targetSpan.Name);
// check the CIEnvironmentValues decoration.
CheckCIEnvironmentValuesDecoration(targetSpan);
// check the runtime values
CheckRuntimeValues(targetSpan);
// check the bundle name
AssertTargetSpanEqual(targetSpan, TestTags.Bundle, TestBundleName);
AssertTargetSpanEqual(targetSpan, TestTags.Module, TestBundleName);
// check the suite name
AssertTargetSpanAnyOf(targetSpan, TestTags.Suite, TestSuiteName, ClassInitializationExceptionTestSuiteName);
// check the test type
AssertTargetSpanEqual(targetSpan, TestTags.Type, TestTags.TypeTest);
// check the test framework
AssertTargetSpanContains(targetSpan, TestTags.Framework, "MSTestV2");
Assert.True(targetSpan.Tags.Remove(TestTags.FrameworkVersion));
// check the version
AssertTargetSpanEqual(targetSpan, "version", "1.0.0");
// checks the runtime id tag
AssertTargetSpanExists(targetSpan, Tags.RuntimeId);
// checks the source tags
AssertTargetSpanExists(targetSpan, TestTags.SourceFile);
// checks code owners
AssertTargetSpanExists(targetSpan, TestTags.CodeOwners);
// checks the origin tag
CheckOriginTag(targetSpan);
// Check the Environment
AssertTargetSpanEqual(targetSpan, Tags.Env, "integration_tests");
// Language
AssertTargetSpanEqual(targetSpan, Tags.Language, TracerConstants.Language);
// CI Library Language
AssertTargetSpanEqual(targetSpan, CommonTags.LibraryVersion, TracerConstants.AssemblyVersion);
// Session data
AssertTargetSpanExists(targetSpan, TestTags.Command);
AssertTargetSpanExists(targetSpan, TestTags.CommandWorkingDirectory);
// Unskippable data
if (targetSpan.Tags[TestTags.Name] != "UnskippableTest")
{
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.UnskippableTag, "false");
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.ForcedRunTag, "false");
}
// check specific test span
switch (targetSpan.Tags[TestTags.Name])
{
case "SimplePassTest":
CheckSimpleTestSpan(targetSpan);
break;
case "SkipByITRSimulation":
AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusSkip);
AssertTargetSpanEqual(targetSpan, TestTags.SkipReason, IntelligentTestRunnerTags.SkippedByReason);
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.SkippedBy, "true");
break;
case "SimpleSkipFromAttributeTest":
CheckSimpleSkipFromAttributeTest(targetSpan);
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.SkippedBy, "false");
break;
case "SimpleErrorTest":
CheckSimpleErrorTest(targetSpan);
break;
case "TraitPassTest":
CheckSimpleTestSpan(targetSpan);
CheckTraitsValues(targetSpan);
break;
case "TraitSkipFromAttributeTest":
CheckSimpleSkipFromAttributeTest(targetSpan);
CheckTraitsValues(targetSpan);
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.SkippedBy, "false");
break;
case "TraitErrorTest":
CheckSimpleErrorTest(targetSpan);
CheckTraitsValues(targetSpan);
break;
case "SimpleParameterizedTest":
CheckSimpleTestSpan(targetSpan);
AssertTargetSpanAnyOf(
targetSpan,
TestTags.Parameters,
"{\"metadata\":{},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}",
"{\"metadata\":{},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}",
"{\"metadata\":{},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}");
break;
case "SimpleSkipParameterizedTest":
CheckSimpleSkipFromAttributeTest(targetSpan);
// On callsite the parameters tags are being sent with no parameters, this is not required due the whole test is skipped.
// That behavior has changed in calltarget.
AssertTargetSpanAnyOf(
targetSpan,
TestTags.Parameters,
"{\"metadata\":{},\"arguments\":{\"xValue\":\"(default)\",\"yValue\":\"(default)\",\"expectedResult\":\"(default)\"}}");
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.SkippedBy, "false");
break;
case "SimpleErrorParameterizedTest":
CheckSimpleErrorTest(targetSpan);
AssertTargetSpanAnyOf(
targetSpan,
TestTags.Parameters,
"{\"metadata\":{},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"0\",\"expectedResult\":\"2\"}}",
"{\"metadata\":{},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"0\",\"expectedResult\":\"4\"}}",
"{\"metadata\":{},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"0\",\"expectedResult\":\"6\"}}");
break;
case "UnskippableTest":
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.UnskippableTag, "true");
AssertTargetSpanEqual(targetSpan, IntelligentTestRunnerTags.ForcedRunTag, "false");
CheckSimpleTestSpan(targetSpan);
break;
case "ClassInitializeExceptionTestMethod":
AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusFail);
targetSpan.Error.Should().Be(1);
AssertTargetSpanEqual(targetSpan, Tags.ErrorType, "Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.TestFailedException");
AssertTargetSpanContains(targetSpan, Tags.ErrorStack, "System.Exception: Class initialize exception");
AssertTargetSpanContains(targetSpan, Tags.ErrorMsg, "Class initialize exception.");
break;
case "My Custom: CustomTestMethodAttributeTest":
case "My Custom 2: CustomRenameTestMethodAttributeTest":
case "My Custom 3|1: CustomMultipleResultsTestMethodAttributeTest":
case "My Custom 3|2: CustomMultipleResultsTestMethodAttributeTest":
AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusPass);
break;
}
// check remaining tag (only the name)
Assert.Single(targetSpan.Tags);
}
}
}
}
catch
{
WriteSpans(spans);
throw;
}
}
}
[CollectionDefinition("MsTestV2Tests", DisableParallelization = true)]
public class MsTestV2TestCollection
{
}
}