Skip to content

Commit

Permalink
test DisplayUnits/DisplayRateTimeScale properties (dotnet/coreclr#25525)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@0d83047
  • Loading branch information
sywhang authored Jul 2, 2019
1 parent 28d0bd2 commit fabf41c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private sealed class SimpleEventSource : EventSource

public SimpleEventSource(string _displayName, string _displayUnits)
{
_myCounter = new IncrementingEventCounter("test-counter", this) { DisplayName = _displayName, DisplayUnits = _displayUnits };
_myCounter = new IncrementingEventCounter("test-counter", this) { DisplayName = _displayName, DisplayUnits = _displayUnits, DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
}

public void IncrementCounter()
Expand All @@ -41,6 +41,7 @@ internal sealed class SimpleEventListener : EventListener
public int incrementSum;
public string displayName;
public string displayUnits;
public string displayRateTimeScale;

public SimpleEventListener(string targetSourceName, EventLevel level)
{
Expand Down Expand Up @@ -84,6 +85,10 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
displayUnits = payload.Value.ToString();
}
else if (payload.Key.Equals("DisplayRateTimeScale"))
{
displayRateTimeScale = payload.Value.ToString();
}
}
}
}
Expand Down Expand Up @@ -126,10 +131,16 @@ public static int Main(string[] args)
if (displayUnits != myListener.displayUnits)
{
Console.WriteLine("Test Failed");
Console.WriteLine($"Expected to see {displayUnits} as DisplayName property in payload - saw {myListener.displayUnits}");
Console.WriteLine($"Expected to see {displayUnits} as DisplayUnits property in payload - saw {myListener.displayUnits}");
return 1;
}

if (!myListener.displayRateTimeScale.Equals("00:00:01"))
{
Console.WriteLine("Test failed");
Console.WriteLine($"Wrong DisplayRateTimeScale: {myListener.displayRateTimeScale}");
}

Console.WriteLine("Test passed");
return 100;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private sealed class SimpleEventSource : EventSource

public SimpleEventSource(Func<double> getMockedCount)
{
_mockedCounter = new IncrementingPollingCounter("failureCount", this, getMockedCount);
_mockedCounter = new IncrementingPollingCounter("failureCount", this, getMockedCount) { DisplayName = "Failure Count", DisplayUnits = "Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
}
}

Expand All @@ -35,6 +35,9 @@ internal sealed class SimpleEventListener : EventListener
public int FailureEventCount { get; private set; } = 0;
public bool Failed = false;
public bool MetadataSet = false;
public string displayName = "";
public string displayRateTimeScale = "";
public string displayUnits = "";

public SimpleEventListener(string targetSourceName, EventLevel level)
{
Expand Down Expand Up @@ -76,6 +79,18 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
increment = payload.Value.ToString();
}
else if (payload.Key.Equals("DisplayRateTimeScale"))
{
displayRateTimeScale = payload.Value.ToString();
}
else if (payload.Key.Equals("DisplayName"))
{
displayName = payload.Value.ToString();
}
else if (payload.Key.Equals("DisplayUnits"))
{
displayUnits = payload.Value.ToString();
}
}

// Check if the mean is what we expect it to be
Expand Down Expand Up @@ -107,16 +122,32 @@ public static int Main(string[] args)
// Want to sleep for 5000 ms to get some counters piling up.
Thread.Sleep(5000);

if (!myListener.Failed && mockedCountCalled > 0)
if (myListener.Failed || mockedCountCalled <= 0)
{
Console.WriteLine("Test Passed");
return 100;
Console.WriteLine($"Test Failed - mockedCountCalled = {mockedCountCalled}, myListener.Failed = {myListener.Failed}");
return 1;
}
else

if (myListener.displayRateTimeScale != "00:00:01")
{
Console.WriteLine($"Test Failed - Incorrect DisplayRateTimeScale in payload: {myListener.displayRateTimeScale}");
return 1;
}

if (myListener.displayName != "Failure Count")
{
Console.WriteLine($"Test Failed - Incorrect DisplayName in payload: {myListener.displayName}");
return 1;
}

if (myListener.displayUnits != "Count")
{
Console.WriteLine("Test Failed");
Console.WriteLine($"Test failed - Incorrect DisplayUnits in payload: {myListener.displayUnits}");
return 1;
}

Console.WriteLine("Test passed");
return 100;
}
}
}
Expand Down

0 comments on commit fabf41c

Please sign in to comment.