Skip to content

Commit bd95698

Browse files
committed
Enable Roslyn analysis - Test Applications - final
1 parent f0a70f7 commit bd95698

File tree

107 files changed

+434
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+434
-218
lines changed

test/IntegrationTests/ContinuousProfilerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ private static bool ContainPeriod(Profile profile, string profilingSampleType, s
112112

113113
private static List<string> CreateExpectedStackTrace()
114114
{
115-
var stackTrace = new List<string>
116-
{
115+
List<string> stackTrace =
116+
[
117117
"System.Threading.Thread.Sleep(System.TimeSpan)",
118118
"TestApplication.ContinuousProfiler.Fs.ClassFs.methodFs(System.String)",
119119
"TestApplication.ContinuousProfiler.Vb.ClassVb.MethodVb(System.String)",
@@ -126,7 +126,7 @@ private static List<string> CreateExpectedStackTrace()
126126
"My.Custom.Test.Namespace.ClassD`21.MethodD(T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Unknown)",
127127
"My.Custom.Test.Namespace.GenericClassC`1.GenericMethodCFromGenericClass[T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Unknown)",
128128
"My.Custom.Test.Namespace.GenericClassC`1.GenericMethodCFromGenericClass(T)"
129-
};
129+
];
130130

131131
#if NETFRAMEWORK || DEBUG
132132
stackTrace.Add("Unknown_Native_Function(unknown)");

test/IntegrationTests/Log4NetBridgeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void SubmitLogs_ThroughLog4NetBridge_WhenLog4NetIsUsedDirectlyForLogging(
3737
// Logged with exception
3838
collector.Expect(
3939
logRecord =>
40-
VerifyBody(logRecord, "Exception occured") &&
40+
VerifyBody(logRecord, "Exception occurred") &&
4141
logRecord is { SeverityText: "ERROR", SeverityNumber: SeverityNumber.Error } &&
4242
VerifyExceptionAttributes(logRecord) &&
4343
logRecord.Attributes.Count == 4,
@@ -69,7 +69,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenLog4NetIsUsedAsILoggerAppenderFo
6969
// Logged in scope of an activity
7070
collector.Expect(
7171
logRecord =>
72-
VerifyBody(logRecord, "{0}, {1} at {2:t}!") &&
72+
VerifyBody(logRecord, "{hello}, {world} at {time:t}!") &&
7373
VerifyTraceContext(logRecord) &&
7474
logRecord is { SeverityText: "Information", SeverityNumber: SeverityNumber.Info } &&
7575
// 0 : "Hello"
@@ -81,7 +81,7 @@ public void SubmitLogs_ThroughILoggerBridge_WhenLog4NetIsUsedAsILoggerAppenderFo
8181
// Logged with exception
8282
collector.Expect(
8383
logRecord =>
84-
VerifyBody(logRecord, "Exception occured") &&
84+
VerifyBody(logRecord, "Exception occurred") &&
8585
// OtlpLogExporter adds exception related attributes (ConsoleExporter doesn't show them)
8686
logRecord is { SeverityText: "Error", SeverityNumber: SeverityNumber.Error } &&
8787
VerifyExceptionAttributes(logRecord) &&
@@ -148,7 +148,7 @@ public void TraceContext_IsInjectedIntoCurrentLog4NetLogsDestination(string pack
148148
var regex = new Regex(@"INFO TestApplication\.Log4NetBridge\.Program - Hello, world at \d{2}\:\d{2}\! span_id=[a-f0-9]{16} trace_id=[a-f0-9]{32} trace_flags=01");
149149
var output = standardOutput;
150150
Assert.Matches(regex, output);
151-
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occured span_id=(null) trace_id=(null) trace_flags=(null)", output);
151+
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occurred span_id=(null) trace_id=(null) trace_flags=(null)", output);
152152
}
153153

154154
private static bool VerifyAttributes(LogRecord logRecord)
@@ -172,7 +172,7 @@ private static bool VerifyTraceContext(LogRecord logRecord)
172172
private static void AssertStandardOutputExpectations(string standardOutput)
173173
{
174174
Assert.Contains("INFO TestApplication.Log4NetBridge.Program - Hello, world at", standardOutput);
175-
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occured", standardOutput);
175+
Assert.Contains("ERROR TestApplication.Log4NetBridge.Program - Exception occurred", standardOutput);
176176
}
177177

178178
private static bool VerifyBody(LogRecord logRecord, string expectedBody)

test/IntegrationTests/MinimalApiTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ public async Task SubmitsLogsWithoutDuplicates(bool enableByteCodeInstrumentatio
5555
collector.AssertCollected();
5656
}
5757

58-
private static bool ValidateCombinedLogsExport(IEnumerable<LogRecord> records)
58+
private static bool ValidateCombinedLogsExport(ICollection<LogRecord> records)
5959
{
6060
return ValidateSingleAppLogExport(records) && ValidateSingleBeforeHostLogRecord(records);
6161
}
6262

63-
private static bool ValidateSingleBeforeHostLogRecord(IEnumerable<LogRecord> records)
63+
private static bool ValidateSingleBeforeHostLogRecord(ICollection<LogRecord> records)
6464
{
6565
var beforeHostLogCount = records.Count(lr => Convert.ToString(lr.Body) == "{ \"stringValue\": \"Logged before host is built.\" }");
6666
return beforeHostLogCount == 1;
6767
}
6868

69-
private static bool ValidateSingleAppLogExport(IEnumerable<LogRecord> records)
69+
private static bool ValidateSingleAppLogExport(ICollection<LogRecord> records)
7070
{
7171
var appLogCount = records.Count(lr => Convert.ToString(lr.Body) == "{ \"stringValue\": \"Request received.\" }");
7272
return appLogCount == 1;

test/IntegrationTests/NLogBridgeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void SubmitLogs_ThroughNLogBridge_WhenNLogIsUsedDirectlyForLogging(string
4646
// Logged with exception
4747
collector.Expect(
4848
logRecord =>
49-
VerifyBody(logRecord, "Exception occured") &&
49+
VerifyBody(logRecord, "Exception occurred") &&
5050
logRecord is { SeverityText: "Error", SeverityNumber: SeverityNumber.Error } &&
5151
VerifyExceptionAttributes(logRecord) &&
5252
logRecord.Attributes.Count == 3,

test/test-applications/integrations/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<!-- CA1031: Do not catch general exception types -->
1717
<!-- CA1303: Do not pass literals as localized parameters -->
1818
<NoWarn>$(NoWarn);CA1031;CA1303</NoWarn>
19+
<AnalysisLevel>latest-All</AnalysisLevel>
1920
</PropertyGroup>
2021
</Project>

test/test-applications/integrations/TestApplication.AssemblyRedirection.NetFramework/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var loadedAssemblyNames = new HashSet<string>();
1010
var hasMultipleInstancesOfSingleAssembly = false;
1111
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
12-
Array.Sort<Assembly>(assemblies, (l, r) => l.FullName?.CompareTo(r.FullName) ?? -1);
12+
Array.Sort<Assembly>(assemblies, static (l, r) => string.CompareOrdinal(l.FullName, r.FullName));
1313
Console.WriteLine("Loaded assemblies:");
1414
foreach (var assembly in assemblies)
1515
{

test/test-applications/integrations/TestApplication.ContinuousProfiler.ContextTracking/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
namespace TestApplication.ContinuousProfiler.ContextTracking;
77

8-
internal class Program
8+
internal static class Program
99
{
1010
private static readonly ActivitySource Source = new ActivitySource("TestApplication.ContinuousProfiler.ContextTracking");
1111

12-
public static async Task Main(string[] args)
12+
public static async Task Main()
1313
{
1414
Thread.CurrentThread.Name = "TestName";
1515
// Start an activity that remains active until async operation completes,

test/test-applications/integrations/TestApplication.ContinuousProfiler.ContextTracking/TestPlugin.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33

44
namespace TestApplication.ContinuousProfiler.ContextTracking;
55

6+
#pragma warning disable CA1515 // Consider making public types internal. Needed for AutoInstrumentation plugin loading.
67
public class TestPlugin
8+
#pragma warning restore CA1515 // Consider making public types internal Needed for AutoInstrumentation plugin loading.
79
{
10+
#pragma warning disable CA1822 // Mark members as static. Needed for AutoInstrumentation plugin loading.
811
public Tuple<bool, uint, bool, uint, TimeSpan, TimeSpan, object> GetContinuousProfilerConfiguration()
12+
#pragma warning restore CA1822 // Mark members as static. Needed for AutoInstrumentation plugin loading.
913
{
1014
var threadSamplingEnabled = true;
1115
var threadSamplingInterval = 1000u;
1216
var allocationSamplingEnabled = false;
1317
var maxMemorySamplesPerMinute = 200u;
1418
var exportInterval = TimeSpan.FromMilliseconds(500);
1519
var exportTimeout = TimeSpan.FromSeconds(5);
20+
#pragma warning disable CA2000 // Dispose objects before losing scope. It should be handled by the AutoInstrumentation.
1621
object continuousProfilerExporter = new OtlpOverHttpExporter(TimeSpan.FromMilliseconds(threadSamplingInterval), new SampleNativeFormatParser());
22+
#pragma warning restore CA2000 // Dispose objects before losing scope. It should be handled by the AutoInstrumentation.
1723

1824
return Tuple.Create(threadSamplingEnabled, threadSamplingInterval, allocationSamplingEnabled, maxMemorySamplesPerMinute, exportInterval, exportTimeout, continuousProfilerExporter);
1925
}

test/test-applications/integrations/TestApplication.ContinuousProfiler/ClassA.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
using System.Globalization;
45
using System.Runtime.CompilerServices;
56
using System.Runtime.InteropServices;
67

@@ -19,7 +20,7 @@ public static void MethodA()
1920
var items = new List<string>();
2021
for (var i = 0; i < numberOfItems; i++)
2122
{
22-
items.Add(i.ToString("D10000"));
23+
items.Add(i.ToString("D10000", CultureInfo.InvariantCulture));
2324
}
2425

2526
MethodABytes(
@@ -76,8 +77,8 @@ public static unsafe void MethodAFloats(
7677
float fl,
7778
double db)
7879
{
79-
int a = 1;
80-
int* pointer = &a;
80+
var a = 1;
81+
var pointer = &a;
8182
MethodAPointer(pointer);
8283
}
8384

@@ -89,8 +90,8 @@ public static unsafe void MethodAPointer(int* pointer)
8990
new object(),
9091
new CustomClass(),
9192
default,
92-
Array.Empty<CustomClass>(),
93-
Array.Empty<CustomStruct>(),
93+
[],
94+
[],
9495
new List<string>());
9596
}
9697

@@ -110,6 +111,7 @@ public static void MethodAOthers<T>(
110111
static void Action(int s) => InternalClassB<string, int>.DoubleInternalClassB.TripleInternalClassB<int>.MethodB(s, [3], TimeSpan.Zero, 0, ["a"], []);
111112
}
112113

114+
[DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
113115
#if NET
114116
[DllImport("TestApplication.ContinuousProfiler.NativeDep")]
115117
#else
@@ -126,7 +128,7 @@ internal static class TripleInternalClassB<T3>
126128
[MethodImpl(MethodImplOptions.NoInlining)]
127129
public static void MethodB<T2>(int testArg, T3[] a, T2 b, T4 t, IList<T1> c, IList<string> d)
128130
{
129-
OTelAutoCallbackTest(TestCallback, testArg);
131+
_ = OTelAutoCallbackTest(TestCallback, testArg);
130132
}
131133
}
132134
}

test/test-applications/integrations/TestApplication.ContinuousProfiler/CustomClass.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
namespace My.Custom.Test.Namespace;
55

6-
internal class CustomClass
7-
{
8-
}
6+
internal sealed class CustomClass;

0 commit comments

Comments
 (0)