Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0.4xx] Fix serialization of TelemetryEventArgs data packets across MSBuild worker nodes #10464

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.11.3</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.11.4</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.10.4</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
Expand Down
1 change: 1 addition & 0 deletions src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ public void PropertyInitialValueEventArgs()
e => e.HelpKeyword,
e => e.SenderName);
}

[Fact]
public void ReadingCorruptedStreamThrows()
{
Expand Down
57 changes: 57 additions & 0 deletions src/Framework.UnitTests/CustomEventArgSerialization_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -974,5 +974,62 @@ private static void VerifyTaskFinished(TaskFinishedEventArgs genericEvent, TaskF
newGenericEvent.TaskFile.ShouldBe(genericEvent.TaskFile, StringCompareShould.IgnoreCase); // "Expected TaskFile to Match"
newGenericEvent.TaskName.ShouldBe(genericEvent.TaskName, StringCompareShould.IgnoreCase); // "Expected TaskName to Match"
}


[Fact]
public void TestTelemetryEventArgs()
{
// Test using reasonable values
TelemetryEventArgs genericEvent = new TelemetryEventArgs { EventName = "Good", Properties = new Dictionary<string, string> { { "Key", "Value" } } };
genericEvent.BuildEventContext = new BuildEventContext(5, 4, 3, 2);

// Serialize
genericEvent.WriteToStream(_writer);
long streamWriteEndPosition = _stream.Position;

// Deserialize and Verify
_stream.Position = 0;
TelemetryEventArgs newGenericEvent = new TelemetryEventArgs();
newGenericEvent.CreateFromStream(_reader, _eventArgVersion);
_stream.Position.ShouldBe(streamWriteEndPosition); // "Stream End Positions Should Match"
VerifyGenericEventArg(genericEvent, newGenericEvent);
VerifyTelemetryEvent(genericEvent, newGenericEvent);

// Test using null event name
baronfel marked this conversation as resolved.
Show resolved Hide resolved
_stream.Position = 0;
genericEvent = new TelemetryEventArgs { EventName = null, Properties = new Dictionary<string, string> { { "Key", "Value" } } };
// Serialize
genericEvent.WriteToStream(_writer);
streamWriteEndPosition = _stream.Position;

// Deserialize and Verify
_stream.Position = 0;
newGenericEvent = new TelemetryEventArgs();
newGenericEvent.CreateFromStream(_reader, _eventArgVersion);
_stream.Position.ShouldBe(streamWriteEndPosition); // "Stream End Positions Should Match"
VerifyGenericEventArg(genericEvent, newGenericEvent);
VerifyTelemetryEvent(genericEvent, newGenericEvent);

// Test using null property value name
_stream.Position = 0;
genericEvent = new TelemetryEventArgs { EventName = "Good", Properties = new Dictionary<string, string> { { "Key", null } } };
// Serialize
genericEvent.WriteToStream(_writer);
streamWriteEndPosition = _stream.Position;

// Deserialize and Verify
_stream.Position = 0;
newGenericEvent = new TelemetryEventArgs();
newGenericEvent.CreateFromStream(_reader, _eventArgVersion);
_stream.Position.ShouldBe(streamWriteEndPosition); // "Stream End Positions Should Match"
VerifyGenericEventArg(genericEvent, newGenericEvent);
VerifyTelemetryEvent(genericEvent, newGenericEvent);
}

private static void VerifyTelemetryEvent(TelemetryEventArgs expected, TelemetryEventArgs actual)
{
actual.EventName.ShouldBe(expected.EventName);
actual.Properties.ShouldBe(expected.Properties);
}
}
}
5 changes: 2 additions & 3 deletions src/Framework/TelemetryEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ internal override void WriteToStream(BinaryWriter writer)
foreach (var kvp in Properties)
{
writer.Write(kvp.Key);
writer.Write(kvp.Value);
writer.WriteOptionalString(kvp.Value);
}
}

internal override void CreateFromStream(BinaryReader reader, int version)
{
base.CreateFromStream(reader, version);
Expand All @@ -51,7 +50,7 @@ internal override void CreateFromStream(BinaryReader reader, int version)
for (int i = 0; i < count; i++)
{
string key = reader.ReadString();
string value = reader.ReadString();
string value = reader.ReadOptionalString();
Properties.Add(key, value);
}
}
Expand Down