perf(worker): exact-format timestamp parse and compiled status-field accessors on the event path
This commit is contained in:
@@ -135,6 +135,90 @@ public sealed class MxStatusProxyConverterTests
|
||||
Assert.Equal("Invalid reference", second.DiagnosticText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies every accessor strategy converts the same status values
|
||||
/// identically. PERF-20 reads a public field of a publicly visible type
|
||||
/// through a delegate compiled from an expression tree instead of
|
||||
/// <c>FieldInfo.GetValue</c>; a field type whose conversion to int is not
|
||||
/// a lossless widening (<see cref="FakeWideStatusProxy"/>) and a type the
|
||||
/// compiled delegate may not touch (<see cref="HiddenStatusProxy"/>, not
|
||||
/// visible outside this assembly) keep the reflection read. All four
|
||||
/// doubles below carry the same logical status, so all four messages must
|
||||
/// be equal.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Convert_AcrossAccessorStrategies_ProducesIdenticalMessages()
|
||||
{
|
||||
// Struct, widening field types: the compiled accessor unboxes in place.
|
||||
MxStatusProxy compiledStruct = _converter.Convert(new FakeMxStatusProxy
|
||||
{
|
||||
success = 1,
|
||||
category = 5,
|
||||
detectedBy = 3,
|
||||
detail = 21,
|
||||
});
|
||||
|
||||
// Reference type, widening field types: the compiled accessor casts.
|
||||
MxStatusProxy compiledClass = _converter.Convert(new FakeStatusProxyClass
|
||||
{
|
||||
success = 1,
|
||||
category = 5,
|
||||
detectedBy = 3,
|
||||
detail = 21,
|
||||
});
|
||||
|
||||
// Non-widening field types: reflection + Convert.ToInt32 is kept.
|
||||
MxStatusProxy reflectedWide = _converter.Convert(new FakeWideStatusProxy
|
||||
{
|
||||
success = 1L,
|
||||
category = 5L,
|
||||
detectedBy = 3L,
|
||||
detail = 21L,
|
||||
});
|
||||
|
||||
// Type not visible outside the assembly: reflection is kept.
|
||||
MxStatusProxy reflectedHidden = _converter.Convert(new HiddenStatusProxy
|
||||
{
|
||||
success = 1,
|
||||
category = 5,
|
||||
detectedBy = 3,
|
||||
detail = 21,
|
||||
});
|
||||
|
||||
Assert.Equal(compiledStruct, compiledClass);
|
||||
Assert.Equal(compiledStruct, reflectedWide);
|
||||
Assert.Equal(compiledStruct, reflectedHidden);
|
||||
Assert.Equal(MxStatusCategory.OperationalError, compiledStruct.Category);
|
||||
Assert.Equal(MxStatusSource.RespondingNmx, compiledStruct.DetectedBy);
|
||||
Assert.Equal("Invalid reference", compiledStruct.DiagnosticText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the compiled accessor widens a negative 16-bit field the way
|
||||
/// <c>Convert.ToInt32</c> did — sign-extended, not reinterpreted. The
|
||||
/// interop MXSTATUS_PROXY declares 16-bit fields, so a sign-extension
|
||||
/// mistake here would silently change every failing status the gateway
|
||||
/// reports.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Convert_WithExtremeInt16FieldValues_SignExtendsLikeConvertToInt32()
|
||||
{
|
||||
FakeMxStatusProxy status = new()
|
||||
{
|
||||
success = short.MinValue,
|
||||
category = 2,
|
||||
detectedBy = 0,
|
||||
detail = short.MaxValue,
|
||||
};
|
||||
|
||||
MxStatusProxy converted = _converter.Convert(status);
|
||||
|
||||
Assert.Equal((int)short.MinValue, converted.Success);
|
||||
Assert.Equal((int)short.MaxValue, converted.Detail);
|
||||
Assert.Equal(MxStatusCategory.Warning, converted.Category);
|
||||
Assert.Equal(MxStatusSource.RequestingLmx, converted.DetectedBy);
|
||||
}
|
||||
|
||||
public struct FakeMxStatusProxy
|
||||
{
|
||||
public short success;
|
||||
@@ -146,6 +230,39 @@ public sealed class MxStatusProxyConverterTests
|
||||
public short detail;
|
||||
}
|
||||
|
||||
public struct FakeWideStatusProxy
|
||||
{
|
||||
public long success;
|
||||
|
||||
public long category;
|
||||
|
||||
public long detectedBy;
|
||||
|
||||
public long detail;
|
||||
}
|
||||
|
||||
public sealed class FakeStatusProxyClass
|
||||
{
|
||||
public int success;
|
||||
|
||||
public int category;
|
||||
|
||||
public int detectedBy;
|
||||
|
||||
public int detail;
|
||||
}
|
||||
|
||||
private struct HiddenStatusProxy
|
||||
{
|
||||
public short success;
|
||||
|
||||
public int category;
|
||||
|
||||
public int detectedBy;
|
||||
|
||||
public short detail;
|
||||
}
|
||||
|
||||
private sealed class MissingFields
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user