Skip to content

Commit f3cd0e7

Browse files
ysolomchenkoKielekCodeBlanch
authored
[Tests] Nullable (open-telemetry#5882)
Co-authored-by: Piotr Kiełkowicz <[email protected]> Co-authored-by: Mikel Blanchard <[email protected]>
1 parent 36d5900 commit f3cd0e7

38 files changed

+211
-173
lines changed

src/Shared/PooledList.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OpenTelemetry.Internal;
1111

1212
internal readonly struct PooledList<T> : IEnumerable<T>, ICollection
1313
{
14-
private static int lastAllocatedSize = 64;
14+
public static int LastAllocatedSize = 64;
1515

1616
private readonly T[] buffer;
1717

@@ -36,7 +36,7 @@ public ref T this[int index]
3636

3737
public static PooledList<T> Create()
3838
{
39-
return new PooledList<T>(ArrayPool<T>.Shared.Rent(lastAllocatedSize), 0);
39+
return new PooledList<T>(ArrayPool<T>.Shared.Rent(LastAllocatedSize), 0);
4040
}
4141

4242
public static void Add(ref PooledList<T> list, T item)
@@ -47,10 +47,10 @@ public static void Add(ref PooledList<T> list, T item)
4747

4848
if (list.Count >= buffer.Length)
4949
{
50-
lastAllocatedSize = buffer.Length * 2;
50+
LastAllocatedSize = buffer.Length * 2;
5151
var previousBuffer = buffer;
5252

53-
buffer = ArrayPool<T>.Shared.Rent(lastAllocatedSize);
53+
buffer = ArrayPool<T>.Shared.Rent(LastAllocatedSize);
5454

5555
var span = previousBuffer.AsSpan();
5656
span.CopyTo(buffer);

test/OpenTelemetry.Tests/Internal/PooledListTest.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System.Collections;
5-
using System.Reflection;
65

76
using Xunit;
87

@@ -44,17 +43,9 @@ public void Verify_CreateAddClear()
4443
[Fact]
4544
public void Verify_AllocatedSize()
4645
{
47-
int GetLastAllocatedSize(PooledList<int> pooledList)
48-
{
49-
var value = typeof(PooledList<int>)
50-
.GetField("lastAllocatedSize", BindingFlags.NonPublic | BindingFlags.Static)
51-
.GetValue(pooledList);
52-
return (int)value;
53-
}
54-
5546
var pooledList = PooledList<int>.Create();
5647

57-
var size = GetLastAllocatedSize(pooledList);
48+
var size = PooledList<int>.LastAllocatedSize;
5849
Assert.Equal(64, size);
5950

6051
// The Add() method has a condition to double the size of the buffer
@@ -65,7 +56,7 @@ int GetLastAllocatedSize(PooledList<int> pooledList)
6556
PooledList<int>.Add(ref pooledList, i);
6657
}
6758

68-
size = GetLastAllocatedSize(pooledList);
59+
size = PooledList<int>.LastAllocatedSize;
6960
Assert.Equal(128, size);
7061
}
7162

test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigParserTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void SelfDiagnosticsConfigParser_TryParseLogLevel()
6969
""FileSize"": 1024,
7070
""LogLevel"": ""Error""
7171
}";
72-
Assert.True(SelfDiagnosticsConfigParser.TryParseLogLevel(configJson, out string logLevelString));
72+
Assert.True(SelfDiagnosticsConfigParser.TryParseLogLevel(configJson, out string? logLevelString));
7373
Assert.Equal("Error", logLevelString);
7474
}
7575
}

test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void SelfDiagnosticsEventListener_constructor_Invalid_Input()
2121
// no configRefresher object
2222
Assert.Throws<ArgumentNullException>(() =>
2323
{
24-
_ = new SelfDiagnosticsEventListener(EventLevel.Error, null);
24+
_ = new SelfDiagnosticsEventListener(EventLevel.Error, null!);
2525
});
2626
}
2727

test/OpenTelemetry.Tests/Internal/WildcardHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void WildcardRegex_ShouldMatch(string[] patterns, string matchWith, bool
3030
[InlineData("a", false)]
3131
[InlineData("a.*", true)]
3232
[InlineData("a.?", true)]
33-
public void Verify_ContainsWildcard(string pattern, bool expected)
33+
public void Verify_ContainsWildcard(string? pattern, bool expected)
3434
{
3535
Assert.Equal(expected, WildcardHelper.ContainsWildcard(pattern));
3636
}

test/OpenTelemetry.Tests/Logs/BatchLogRecordExportProcessorTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,23 @@ public void StateValuesAndScopeBufferingTest()
4343
Assert.NotNull(logRecord.AttributeStorage);
4444
Assert.NotNull(logRecord.ILoggerData.BufferedScopes);
4545

46-
KeyValuePair<string, object> actualState = logRecord.StateValues[0];
46+
KeyValuePair<string, object?> actualState = logRecord.StateValues[0];
4747

4848
Assert.Same("Value", actualState.Key);
4949
Assert.Same("Hello world", actualState.Value);
5050

51+
int scopeCount = 0;
5152
bool foundScope = false;
5253

53-
logRecord.ForEachScope<object>(
54+
logRecord.ForEachScope<object?>(
5455
(s, o) =>
5556
{
5657
foundScope = ReferenceEquals(s.Scope, exportedItems);
58+
scopeCount++;
5759
},
5860
null);
5961

62+
Assert.Equal(1, scopeCount);
6063
Assert.True(foundScope);
6164

6265
processor.Shutdown();

0 commit comments

Comments
 (0)