diff --git a/Directory.Packages.props b/Directory.Packages.props index 86864e2b8..850902ccc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ true - + @@ -29,18 +29,18 @@ - - + + - + - + @@ -54,7 +54,7 @@ - + @@ -63,18 +63,18 @@ - - - - - - - - - + + + + + + + + + - - + + @@ -117,7 +117,7 @@ - + diff --git a/build/scripts/Tooling.fs b/build/scripts/Tooling.fs index 445111974..d91bee954 100644 --- a/build/scripts/Tooling.fs +++ b/build/scripts/Tooling.fs @@ -20,33 +20,30 @@ module Tooling = let private defaultConsoleWriter = Some(ConsoleOutColorWriter() :> IConsoleOutWriter) - let private readInWithTimeout timeout workingDir bin (writer: IConsoleOutWriter option) args = + let private readInWithTimeout (timeout :TimeSpan) workingDir bin (writer: IConsoleOutWriter option) args = let startArgs = StartArguments(bin, args |> List.toArray) + startArgs.Timeout <- timeout + startArgs.ConsoleOutWriter <- Option.defaultValue (NoopWriter()) writer if (Option.isSome workingDir) then startArgs.WorkingDirectory <- Option.defaultValue "" workingDir - let result = Proc.Start(startArgs, timeout, Option.defaultValue (NoopWriter()) writer) + let result = Proc.Start(startArgs) if not result.Completed then failwithf "process failed to complete within %O: %s" timeout bin if not result.ExitCode.HasValue then failwithf "process yielded no exit code: %s" bin { ExitCode = result.ExitCode.Value; Output = seq result.ConsoleOut} - - let private read bin args = readInWithTimeout defaultTimeout None bin defaultConsoleWriter args - let private readQuiet bin args = readInWithTimeout defaultTimeout None bin None args - - let private execInWithTimeout timeout workingDir bin args = + + let private execInWithTimeout (timeout :TimeSpan) workingDir bin args = let startArgs = ExecArguments(bin, args |> List.toArray) + startArgs.Timeout <- timeout if (Option.isSome workingDir) then startArgs.WorkingDirectory <- Option.defaultValue "" workingDir - let result = Proc.Exec(startArgs, timeout) + let result = Proc.Exec(startArgs) try - if not result.HasValue || result.Value > 0 then - failwithf "process returned %i: %s" result.Value bin + if result > 0 then + failwithf "process returned %i: %s" result bin with | :? ProcExecException as ex -> failwithf "%s" ex.Message - let private execIn workingDir bin args = execInWithTimeout defaultTimeout workingDir bin args - let private exec bin args = execIn None bin args - type BuildTooling(timeout, path) = let timeout = match timeout with | Some t -> t | None -> defaultTimeout member this.Path = path diff --git a/dotnet-tools.json b/dotnet-tools.json index e5fd17baf..fd336aeb5 100644 --- a/dotnet-tools.json +++ b/dotnet-tools.json @@ -9,7 +9,7 @@ ] }, "minver-cli": { - "version": "4.3.0", + "version": "6.0.0", "commands": [ "minver" ] diff --git a/src/Elastic.Apm/Elastic.Apm.csproj b/src/Elastic.Apm/Elastic.Apm.csproj index 361acc507..c23a8041e 100644 --- a/src/Elastic.Apm/Elastic.Apm.csproj +++ b/src/Elastic.Apm/Elastic.Apm.csproj @@ -46,6 +46,7 @@ + diff --git a/test/Elastic.Apm.Tests.Utilities/ShouldWaitDurationExtensions.cs b/test/Elastic.Apm.Tests.Utilities/ShouldWaitDurationExtensions.cs index d35953114..e91c8c2af 100644 --- a/test/Elastic.Apm.Tests.Utilities/ShouldWaitDurationExtensions.cs +++ b/test/Elastic.Apm.Tests.Utilities/ShouldWaitDurationExtensions.cs @@ -9,13 +9,13 @@ namespace Elastic.Apm.Tests.Utilities { public static class ShouldWaitDurationExtensions { - public static AndConstraint> + public static AndConstraint> BeGreaterOrEqualToMinimumSleepLength(this NullableNumericAssertions duration) => - duration.NotBeNull().And.BeGreaterOrEqualTo(WaitHelpers.SleepLength); + duration.NotBeNull().And.BeGreaterOrEqualTo(WaitHelpers.SleepLength); - public static AndConstraint> BeGreaterOrEqualToMinimumSleepLength(this NullableNumericAssertions duration, - int numberOfSleeps - ) + public static AndConstraint> BeGreaterOrEqualToMinimumSleepLength( + this NullableNumericAssertions duration, + int numberOfSleeps) { var expectedTransactionLength = numberOfSleeps * WaitHelpers.SleepLength; return duration.NotBeNull() diff --git a/test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs b/test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs index 8332ea684..ccee058a2 100644 --- a/test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs +++ b/test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs @@ -67,7 +67,7 @@ static DockerUtils() { try { - var result = Proc.Start(new StartArguments("docker", "--version"), TimeSpan.FromSeconds(30)); + var result = Proc.Start(new StartArguments("docker", "--version") { Timeout = TimeSpan.FromSeconds(30) }); HasDockerInstalled = result.ExitCode == 0; } catch (Exception) diff --git a/test/Elastic.Apm.Tests/BackendCommTests/CentralConfig/CentralConfigResponseParserTests.cs b/test/Elastic.Apm.Tests/BackendCommTests/CentralConfig/CentralConfigResponseParserTests.cs index a0b8ed89a..ea66a245d 100644 --- a/test/Elastic.Apm.Tests/BackendCommTests/CentralConfig/CentralConfigResponseParserTests.cs +++ b/test/Elastic.Apm.Tests/BackendCommTests/CentralConfig/CentralConfigResponseParserTests.cs @@ -305,7 +305,7 @@ public static IEnumerable ConfigDeltaData { cfg.LogLevel.Should() .NotBeNull() - .And.Be(value); + .And.Be((LogLevel)value); }) }; } diff --git a/test/Elastic.Apm.Tests/BackendCommTests/PayloadSenderTests.cs b/test/Elastic.Apm.Tests/BackendCommTests/PayloadSenderTests.cs index a83e0d1a0..4bd44a4a2 100644 --- a/test/Elastic.Apm.Tests/BackendCommTests/PayloadSenderTests.cs +++ b/test/Elastic.Apm.Tests/BackendCommTests/PayloadSenderTests.cs @@ -320,7 +320,7 @@ public static IEnumerable FlushInterval_test_variants() [Theory] [MemberData(nameof(FlushInterval_test_variants))] - internal async void FlushInterval_test(TestArgs args, int numberOfEventsToSend) + internal async Task FlushInterval_test(TestArgs args, int numberOfEventsToSend) { var batchSentBarrier = new Barrier(2); var barrierTimeout = 30.Seconds(); diff --git a/test/Elastic.Apm.Tests/Config/ConfigTests.cs b/test/Elastic.Apm.Tests/Config/ConfigTests.cs index 7a7b829d3..e63e39d74 100644 --- a/test/Elastic.Apm.Tests/Config/ConfigTests.cs +++ b/test/Elastic.Apm.Tests/Config/ConfigTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Elastic.Apm.Config; using Elastic.Apm.Helpers; using Elastic.Apm.Logging; @@ -30,7 +31,7 @@ namespace Elastic.Apm.Tests.Config [Collection("UsesEnvironmentVariables")] public class ConfigTests : IDisposable { - public static TheoryData GlobalLabelsValidVariantsToTest => new TheoryData> + public static TheoryData> GlobalLabelsValidVariantsToTest => new TheoryData> { // empty string - zero key value pairs { "", new Dictionary() }, diff --git a/test/Elastic.Apm.Tests/Extensions/EnumerableExtensionsTests.cs b/test/Elastic.Apm.Tests/Extensions/EnumerableExtensionsTests.cs index 7488f40d3..c992ba20e 100644 --- a/test/Elastic.Apm.Tests/Extensions/EnumerableExtensionsTests.cs +++ b/test/Elastic.Apm.Tests/Extensions/EnumerableExtensionsTests.cs @@ -14,7 +14,7 @@ namespace Elastic.Apm.Tests.Extensions { public class EnumerableExtensionsTests { - public static TheoryData EnumerablesToTest => new TheoryData, object[]> + public static TheoryData, object[]> EnumerablesToTest => new TheoryData, object[]> { { Array.Empty(), Array.Empty() }, { Enumerable.Range(0, 0).Select(i => (object)i), Array.Empty() }, diff --git a/test/Elastic.Apm.Tests/HelpersTests/AgentSpinLockTests.cs b/test/Elastic.Apm.Tests/HelpersTests/AgentSpinLockTests.cs index 99f9af7fa..f4cf966cb 100644 --- a/test/Elastic.Apm.Tests/HelpersTests/AgentSpinLockTests.cs +++ b/test/Elastic.Apm.Tests/HelpersTests/AgentSpinLockTests.cs @@ -29,7 +29,7 @@ public class AgentSpinLockTests : LoggingTestBase public AgentSpinLockTests(ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper) => _logger = LoggerBase.Scoped(ThisClassName); - internal interface ISpinLockForTest + public interface ISpinLockForTest { void Release(); @@ -45,7 +45,7 @@ internal interface ISpinLockForTest new NoopSpinLockForTest() }; - public static TheoryData ThreadSafeSpinLockImpls => new TheoryData { new AgentSpinLockForTest() }; + public static TheoryData ThreadSafeSpinLockImpls => [new AgentSpinLockForTest()]; [Fact] public void default_value_is_false() diff --git a/test/Elastic.Apm.Tests/HelpersTests/ExceptionUtilsTests.cs b/test/Elastic.Apm.Tests/HelpersTests/ExceptionUtilsTests.cs index d36f5912c..61af79273 100644 --- a/test/Elastic.Apm.Tests/HelpersTests/ExceptionUtilsTests.cs +++ b/test/Elastic.Apm.Tests/HelpersTests/ExceptionUtilsTests.cs @@ -14,7 +14,7 @@ namespace Elastic.Apm.Tests.HelpersTests { public class ExceptionUtilsTests { - public static TheoryData DoSwallowingExceptionsVariantsToTest => new TheoryData + public static TheoryData DoSwallowingExceptionsVariantsToTest => new TheoryData { { ExceptionUtils.MethodExitingNormallyMsgFmt, () => { } }, { ExceptionUtils.MethodExitingCancelledMsgFmt, () => new CancellationToken(true).ThrowIfCancellationRequested() }, diff --git a/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTests.cs b/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTests.cs index ec2f1f0b1..51e37f326 100644 --- a/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTests.cs +++ b/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTests.cs @@ -14,7 +14,7 @@ namespace Elastic.Apm.Tests.HelpersTests { public class LazyContextualInitTests { - public static TheoryData WaysToCallInit = new TheoryData> + public static readonly TheoryData WaysToCallInit = new TheoryData>() { { "IfNotInited?.Init ?? false", (lazyCtxInit, initAction) => lazyCtxInit.IfNotInited?.Init(initAction) ?? false }, { "Init", (lazyCtxInit, initAction) => lazyCtxInit.Init(initAction) } @@ -22,8 +22,8 @@ public class LazyContextualInitTests [Theory] [MemberData(nameof(WaysToCallInitOrGetString))] - internal void with_result_initialized_only_once_on_first_call(string dbgWayToCallDesc - , Func, Func, string> wayToCall + internal void with_result_initialized_only_once_on_first_call(string dbgWayToCallDesc, + Func, Func, string> wayToCall ) { var counter = new ThreadSafeIntCounter(); @@ -58,7 +58,9 @@ internal void with_result_multiple_threads(string dbgWayToCallDesc, Func wayToCall) { var counter = new ThreadSafeIntCounter(); @@ -81,7 +83,9 @@ internal void no_result_initialized_only_once_on_first_call(string dbgWayToCallD } [Theory] +#pragma warning disable xUnit1037 // There are fewer theory data type arguments than required by the parameters of the test method [MemberData(nameof(WaysToCallInit))] +#pragma warning restore xUnit1037 // There are fewer theory data type arguments than required by the parameters of the test method internal void no_result_multiple_threads(string dbgWayToCallDesc, Func wayToCall) { var counter = new ThreadSafeIntCounter(); diff --git a/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTestsHelpers.cs b/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTestsHelpers.cs new file mode 100644 index 000000000..c587fc7d3 --- /dev/null +++ b/test/Elastic.Apm.Tests/HelpersTests/LazyContextualInitTestsHelpers.cs @@ -0,0 +1,15 @@ +using System; +using Elastic.Apm.Helpers; +using Xunit; +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +internal static class LazyContextualInitTestsHelpers +{ + public static TheoryData> WaysToCallInit = new() + { + { "IfNotInited?.Init ?? false", (lazyCtxInit, initAction) => lazyCtxInit.IfNotInited?.Init(initAction) ?? false }, + { "Init", (lazyCtxInit, initAction) => lazyCtxInit.Init(initAction) } + }; +} diff --git a/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs b/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs index 54ace11cb..c131d3dae 100644 --- a/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs +++ b/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs @@ -14,7 +14,7 @@ public class TimeUtilsTests { private static readonly DateTime UnixEpochDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - public static TheoryData TimestampAndDateTimeVariantsToTest => new TheoryData + public static TheoryData TimestampAndDateTimeVariantsToTest => new TheoryData { { 0, UnixEpochDateTime }, { 1, UnixEpochDateTime + TimeUtils.TimeSpanFromFractionalMilliseconds(0.001) }, diff --git a/test/Elastic.Apm.Tests/SamplerTests.cs b/test/Elastic.Apm.Tests/SamplerTests.cs index f63d0283d..b1d39416f 100644 --- a/test/Elastic.Apm.Tests/SamplerTests.cs +++ b/test/Elastic.Apm.Tests/SamplerTests.cs @@ -16,7 +16,7 @@ namespace Elastic.Apm.Tests public class SamplerTests { // ReSharper disable once MemberCanBePrivate.Global - public static TheoryData RateVariantsToTest => new TheoryData + public static TheoryData RateVariantsToTest => new TheoryData { 0, 0.0001, diff --git a/test/Elastic.Apm.Tests/SerializationTests.cs b/test/Elastic.Apm.Tests/SerializationTests.cs index 7ae39c0e1..d24381168 100644 --- a/test/Elastic.Apm.Tests/SerializationTests.cs +++ b/test/Elastic.Apm.Tests/SerializationTests.cs @@ -31,7 +31,7 @@ public SerializationTests() => _payloadItemSerializer = new PayloadItemSerializer(); // ReSharper disable once MemberCanBePrivate.Global - public static TheoryData SerializationUtilsTrimToPropertyMaxLengthVariantsToTest => new TheoryData + public static TheoryData SerializationUtilsTrimToPropertyMaxLengthVariantsToTest => new TheoryData { { "", "" }, { "A", "A" }, diff --git a/test/iis/Elastic.Apm.AspNetFullFramework.Tests/TestsBase.cs b/test/iis/Elastic.Apm.AspNetFullFramework.Tests/TestsBase.cs index 3612af656..636b01c3f 100644 --- a/test/iis/Elastic.Apm.AspNetFullFramework.Tests/TestsBase.cs +++ b/test/iis/Elastic.Apm.AspNetFullFramework.Tests/TestsBase.cs @@ -322,7 +322,7 @@ int expectedStatusCode (int)response.StatusCode, response.StatusCode); try { - response.StatusCode.Should().Be(expectedStatusCode); + response.StatusCode.Should().Be((HttpStatusCode)expectedStatusCode); } catch (XunitException ex) { diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs index dd6f5ca78..34bee5535 100644 --- a/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs +++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/BodyCapturingTests.cs @@ -95,7 +95,7 @@ public async Task ComplexDataSendCaptureBody() var result = await sutEnv.HttpClient.PostAsync("api/Home/Send", new StringContent(body, Encoding.UTF8, "application/json")); // make sure the sample app received the data - result.StatusCode.Should().Be(200); + result.StatusCode.Should().Be((HttpStatusCode)200); // and make sure the data is captured by the agent sutEnv.MockPayloadSender.FirstTransaction.Should().NotBeNull(); diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/AspNetCore/AspNetCoreTests.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/AspNetCore/AspNetCoreTests.cs index eb744f155..38e1889c2 100644 --- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/AspNetCore/AspNetCoreTests.cs +++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/AspNetCore/AspNetCoreTests.cs @@ -26,7 +26,7 @@ public class AspNetCoreTests /// [Theory] [InlineData("net8.0")] - public async void AspNetCoreTest(string framework) + public async System.Threading.Tasks.Task AspNetCoreTest(string framework) { var apmLogger = new InMemoryBlockingLogger(Logging.LogLevel.Error); var apmServer = new MockApmServer(apmLogger, nameof(AspNetCoreTests)); diff --git a/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs b/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs index 43cb28b3a..0f6758bd8 100644 --- a/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs +++ b/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs @@ -73,10 +73,11 @@ private bool TryPublish() var startArgs = new StartArguments("dotnet", args) { - WorkingDirectory = workingDirectory + WorkingDirectory = workingDirectory, + Timeout = TimeSpan.FromSeconds(30) }; - var publishResult = Proc.Start(startArgs, TimeSpan.FromSeconds(30)); + var publishResult = Proc.Start(startArgs); foreach (var line in publishResult.ConsoleOut) { @@ -193,8 +194,9 @@ public static DotnetProject Create(ITestOutputHelper output, string name, string var result = Proc.Start(new StartArguments("dotnet", args) { - WorkingDirectory = directory - }, TimeSpan.FromSeconds(30)); + WorkingDirectory = directory, + Timeout = TimeSpan.FromSeconds(30) + }); if (result.Completed) {