Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace System.Diagnostics.Tests
//Complex types are not supported on EventSource for .NET 4.5
public class DiagnosticSourceEventSourceBridgeTests
{
// Use a longer timeout than the RemoteExecutor default because some of these tests
// can be slow to run on resource constrained CI machines.
// Ensure RemoteExecutor.IsSupported, otherwise remote execution can throw PlatformNotSupportedException.
private static readonly RemoteInvokeOptions? s_remoteInvokeOptions = RemoteExecutor.IsSupported ? new RemoteInvokeOptions { TimeOut = 180_000 } : null;

// To avoid interactions between tests when they are run in parallel, we run all these tests in their
// own sub-process using RemoteExecutor.Invoke() However this makes it very inconvenient to debug the test.
// By setting this #if to true you stub out RemoteInvoke and the code will run in-proc which is useful
Expand Down Expand Up @@ -69,7 +74,7 @@ public void TestEnableAllActivitySourcesAllEvents()
sources[i].Dispose();
}

}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -122,7 +127,7 @@ public void TestEnableAllActivitySourcesWithOneEvent(string eventName)
Assert.Equal(eventsCount, eventSourceListener.EventCount);
sources[i].Dispose();
}
}, eventName).Dispose();
}, eventName, s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -154,7 +159,7 @@ public void TestEnableAllActivitySourcesWithSpecificSamplingResult(string sampli

Assert.Equal(2, eventSourceListener.EventCount);
ValidateActivityEvents(eventSourceListener, "ActivityStop", source.Name, activity.OperationName);
}, samplingResult, alldataRequested.ToString(), activityTraceFlags.ToString()).Dispose();
}, samplingResult, alldataRequested.ToString(), activityTraceFlags.ToString(), s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -194,7 +199,7 @@ public void TestDefaultActivitySource(string eventName, string samplingResult, b
Activity activity = source.StartActivity($"ActivityFromNoneDefault"); // Shouldn't fire any event
Assert.Equal(eCount, eventSourceListener.EventCount);
Assert.Null(activity);
}, eventName, samplingResult, allDataRequested.ToString()).Dispose();
}, eventName, samplingResult, allDataRequested.ToString(), s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -231,7 +236,7 @@ public void TestMultipleSpecs(string spec, bool isAllDataRequestedFromSpecific,
a2.Dispose();
Assert.Equal(4, eventSourceListener.EventCount);

}, spec, isAllDataRequestedFromSpecific.ToString(), isAllDataRequestedFromNoneSpecific.ToString()).Dispose();
}, spec, isAllDataRequestedFromSpecific.ToString(), isAllDataRequestedFromNoneSpecific.ToString(), s_remoteInvokeOptions).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -295,7 +300,7 @@ public void TestTransformSpecs()
Assert.Equal(a.ParentSpanId.ToString(), eventSourceListener.LastEvent.Arguments["ParentSpanId"]);
}

}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}


Expand Down Expand Up @@ -378,7 +383,7 @@ public void TestFilteringWithActivityName()
Assert.Null(a);
}

}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

internal void ValidateActivityEvents(TestDiagnosticSourceEventListener eventSourceListener, string eventName, string sourceName, string activityName)
Expand Down Expand Up @@ -470,7 +475,7 @@ public void TestSpecificEvents()
{
Assert.True(!listen.Name.StartsWith("BuildTestSource"));
}));
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -504,7 +509,7 @@ public void TestBaseClassProperties()
Assert.Equal("Second url", eventSourceListener.LastEvent.Arguments["Url_2"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -537,7 +542,7 @@ public void TestBaseClassDuplicateProperties()
Assert.Equal("MyUrl", eventSourceListener.LastEvent.Arguments["Url"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -596,7 +601,7 @@ public void LinuxNewLineConventions()
{
Assert.True(!listen.Name.StartsWith("BuildTestSource"));
}));
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -660,7 +665,7 @@ public void TestWildCardSourceName()
Assert.Equal("122", eventSourceListener.LastEvent.Arguments["prop222"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -745,7 +750,7 @@ public void TestWildCardEventName()
}
Assert.Equal(0, eventSourceListener.EventCount); // No Event should be fired.
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

public class PropertyThrow
Expand Down Expand Up @@ -777,7 +782,7 @@ public void TestWithPropertyThrowing()
Assert.Equal("", eventSourceListener.LastEvent.Arguments["property2"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -859,7 +864,7 @@ public void TestNulls()
Assert.Equal("8", eventSourceListener.LastEvent.Arguments["cls_Point_X"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -893,7 +898,7 @@ public void TestNoImplicitTransforms()
Assert.Equal("MyUrl", eventSourceListener.LastEvent.Arguments["Url"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -927,7 +932,7 @@ public void TestBadProperties()
Assert.Equal("4", eventSourceListener.LastEvent.Arguments["propInt"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

// Tests that messages about DiagnosticSourceEventSource make it out.
Expand Down Expand Up @@ -958,7 +963,7 @@ public void TestMessages()
Assert.Equal(0, eventSourceListener.EventCount);
Assert.True(3 <= messages.Count);
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

// Tests that version event from DiagnosticSourceEventSource is fired.
Expand Down Expand Up @@ -994,7 +999,7 @@ public void TestVersion()
new Version(typeof(Activity).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "0.0.0").ToString(3),
version.ToString());
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -1067,7 +1072,7 @@ public void TestActivities()
Assert.Equal("stop", eventSourceListener.LastEvent.Arguments["propStr"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

/// <summary>
Expand Down Expand Up @@ -1191,7 +1196,7 @@ public void TestShortcutKeywords()
Assert.Equal("200", eventSourceListener.LastEvent.Arguments["StatusCode"]);
eventSourceListener.ResetEventCountAndLastEvent();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[OuterLoop("Runs for several seconds")]
Expand Down Expand Up @@ -1224,7 +1229,7 @@ public void Stress_WriteConcurrently_DoesntCrash()
}
ce.Wait();
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -1261,7 +1266,7 @@ public void IndexGetters_DontThrow()
Assert.Equal("2", eventListener.LastEvent.Arguments["OtherNumber"]);
Assert.Equal("2", eventListener.LastEvent.Arguments["Count"]);
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -1316,7 +1321,7 @@ public void ActivityObjectsAreInspectable()
AssertActivityMatchesEvent(activity1, eventListener.LastEvent, isStart: false);

}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

private void AssertActivityMatchesEvent(Activity a, DiagnosticSourceEvent e, bool isStart)
Expand Down Expand Up @@ -1405,7 +1410,7 @@ public void TestRuleWithWildcardSourceAndActivityNameIsIgnored()
using var root = a.Source.StartActivity("TestName");

Assert.Null(root);
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -1438,7 +1443,7 @@ public void TestMultipleRulesOnlyFirstTaken(string spec, string errorMessage)
root.Stop();

Assert.Equal(1, eventSourceListener.EventCount);
}, spec, errorMessage).Dispose();
}, spec, errorMessage, s_remoteInvokeOptions).Dispose();
}

[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down Expand Up @@ -1484,7 +1489,7 @@ public void TestRateLimitingSampler(int maxOperationPerSecond)

using var child = a.Source.StartActivity("child");
Assert.NotNull(child); // Child should be created as the parent is recorded.
}, maxOperationPerSecond.ToString(CultureInfo.InvariantCulture)).Dispose();
}, maxOperationPerSecond.ToString(CultureInfo.InvariantCulture), s_remoteInvokeOptions).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand All @@ -1511,7 +1516,7 @@ public void TestParentRatioSampler()
using var child = a.Source.StartActivity("child");

Assert.Null(child);
}).Dispose();
}, s_remoteInvokeOptions).Dispose();

RemoteExecutor.Invoke(() =>
{
Expand All @@ -1534,7 +1539,7 @@ public void TestParentRatioSampler()
Assert.NotNull(child);
Assert.True(child.Recorded);

}).Dispose();
}, s_remoteInvokeOptions).Dispose();

RemoteExecutor.Invoke(() =>
{
Expand Down Expand Up @@ -1568,7 +1573,7 @@ public void TestParentRatioSampler()
(long)(0.0001D * long.MaxValue),
parentContext: default,
notSampledtraceId));
}).Dispose();
}, s_remoteInvokeOptions).Dispose();

RemoteExecutor.Invoke(() =>
{
Expand Down Expand Up @@ -1602,7 +1607,7 @@ public void TestParentRatioSampler()
(long)(0.0001D * long.MaxValue),
parentContext: default,
sampledtraceId));
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand All @@ -1627,7 +1632,7 @@ public void TestSamplingPrecedence()
Assert.NotNull(a);
Assert.False(a.Recorded);
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();

RemoteExecutor.Invoke(() =>
{
Expand All @@ -1648,7 +1653,7 @@ public void TestSamplingPrecedence()
Assert.NotNull(a);
Assert.False(a.Recorded);
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();

RemoteExecutor.Invoke(() =>
{
Expand All @@ -1669,7 +1674,7 @@ public void TestSamplingPrecedence()
Assert.NotNull(a);
Assert.False(a.Recorded);
}
}).Dispose();
}, s_remoteInvokeOptions).Dispose();
}
}

Expand Down
Loading