diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 63b7bf8..81d0bfc 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -17,6 +17,11 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.x + - name: Setup .NET Core 6.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '6.0.x' + include-prerelease: true - uses: actions/checkout@v1 # This test constantly passes localy (windows + linux) but fails in the test environment. Don't have the time/ inclination to figure out why this is right now.. - run: dotnet test -c "Debug" --filter Name!=When_blocking_work_is_executed_on_the_thread_pool_then_thread_pool_delays_are_measured diff --git a/src/prometheus-net.DotNetRuntime.Tests/EventListening/TestHelpers.cs b/src/prometheus-net.DotNetRuntime.Tests/EventListening/TestHelpers.cs index f63abeb..bb6f57e 100644 --- a/src/prometheus-net.DotNetRuntime.Tests/EventListening/TestHelpers.cs +++ b/src/prometheus-net.DotNetRuntime.Tests/EventListening/TestHelpers.cs @@ -12,18 +12,30 @@ public class TestHelpers { public static EventWrittenEventArgs CreateEventWrittenEventArgs(int eventId, DateTime? timestamp = null, params object[] payload) { - var args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new []{ typeof(EventSource)}, Flags.NonPublic | Flags.Instance, new object[] { null}); - args.SetPropertyValue("EventId", eventId); + EventWrittenEventArgs args; + var bindFlags = Flags.NonPublic | Flags.Instance; + + // In .NET 6.0, they changed the signature of these constructors- handle this annoyance + if (typeof(EventWrittenEventArgs).GetConstructors(bindFlags).Any(x => x.GetParameters().Length == 1)) + { + args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new[] { typeof(EventSource)}, Flags.NonPublic | Flags.Instance, new object[] { null }); + args.SetPropertyValue("EventId", eventId); + } + else + { + args = (EventWrittenEventArgs)typeof(EventWrittenEventArgs).CreateInstance(new[] { typeof(EventSource), typeof(int) }, Flags.NonPublic | Flags.Instance, new object[] { null, eventId }); + } + args.SetPropertyValue("Payload", new ReadOnlyCollection(payload)); if (timestamp.HasValue) { args.SetPropertyValue("TimeStamp", timestamp.Value); } - + return args; } - + public static EventWrittenEventArgs CreateCounterEventWrittenEventArgs(params (string key, object val)[] payload) { var counterPayload = payload.ToDictionary(k => k.key, v => v.val); @@ -41,14 +53,11 @@ public static EventAssertion ArrangeEventAssertion(Action> wireU public class EventAssertion { private Action _handler; - + public EventAssertion(Action> wireUp) { - _handler = e => - { - History.Add(e); - }; - + _handler = e => { History.Add(e); }; + wireUp(_handler); } diff --git a/src/prometheus-net.DotNetRuntime.Tests/prometheus-net.DotNetRuntime.Tests.csproj b/src/prometheus-net.DotNetRuntime.Tests/prometheus-net.DotNetRuntime.Tests.csproj index 83c6b6a..5b71de7 100644 --- a/src/prometheus-net.DotNetRuntime.Tests/prometheus-net.DotNetRuntime.Tests.csproj +++ b/src/prometheus-net.DotNetRuntime.Tests/prometheus-net.DotNetRuntime.Tests.csproj @@ -2,11 +2,12 @@ - netcoreapp3.1;net5.0 + netcoreapp3.1;net5.0;net6.0 false Prometheus.DotNetRuntime.Tests AnyCPU true + 10 diff --git a/src/prometheus-net.DotNetRuntime/EventListening/EventParserTypes.cs b/src/prometheus-net.DotNetRuntime/EventListening/EventParserTypes.cs index 7dfeedd..6075671 100644 --- a/src/prometheus-net.DotNetRuntime/EventListening/EventParserTypes.cs +++ b/src/prometheus-net.DotNetRuntime/EventListening/EventParserTypes.cs @@ -87,8 +87,16 @@ internal static IEnumerable GetEventParsers(Assembly fromAssembly) internal static Lazy CurrentRuntimeVerison = new Lazy(() => { var split = RuntimeInformation.FrameworkDescription.Split(' '); - - if (Version.TryParse(split[split.Length - 1], out var version)) + if (split.Length < 2) + return null; + + var versionPart = split[^1]; + // Handle preview version strings, e.g. .NET 6.0.0-preview.7.21377.19. + var hyphenIndex = versionPart.IndexOf('-'); + if (hyphenIndex > -1) + versionPart = versionPart.Substring(0, hyphenIndex); + + if (Version.TryParse(versionPart, out var version)) return new Version(version.Major, version.Minor); return null; diff --git a/src/prometheus-net.DotNetRuntime/ListenerRegistration.cs b/src/prometheus-net.DotNetRuntime/ListenerRegistration.cs index 2fada10..505ad80 100644 --- a/src/prometheus-net.DotNetRuntime/ListenerRegistration.cs +++ b/src/prometheus-net.DotNetRuntime/ListenerRegistration.cs @@ -26,10 +26,8 @@ public static ListenerRegistration Create(CaptureLevel level, Func (object)factory(sp)); }