diff --git a/Directory.Build.targets b/Directory.Build.targets index 6acf57e53..2b5f9c09d 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -30,6 +30,12 @@ + + + + + + - + - + - + - + - + @@ -81,7 +81,7 @@ - + diff --git a/test/FunctionalTests/Balancer/DnsResolverTests.cs b/test/FunctionalTests/Balancer/DnsResolverTests.cs index 0234a5709..5f980240d 100644 --- a/test/FunctionalTests/Balancer/DnsResolverTests.cs +++ b/test/FunctionalTests/Balancer/DnsResolverTests.cs @@ -275,7 +275,7 @@ public async Task RefreshAsync_MultipleCallsThenCancellation_CallCanceled() var dnsResolver = CreateDnsResolver(new Uri("dns:///localhost")); dnsResolver.Start(r => { - tcs.SetResult(r); + tcs.TrySetResult(r); }); // Act @@ -286,13 +286,19 @@ public async Task RefreshAsync_MultipleCallsThenCancellation_CallCanceled() Assert.Greater(result.Addresses!.Count, 0); // Wait for the internal resolve task to be completed before triggering refresh again + Logger.LogInformation("Wait for DNS resolver resolve task to complete."); await dnsResolver._resolveTask.DefaultTimeout(); + + Logger.LogInformation("Recreate TCS and refresh resolver again."); tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); dnsResolver.Refresh(); + Logger.LogInformation("Dispose resolver while refresh is in progress. The refresh should be waiting for the min interval to complete."); dnsResolver.Dispose(); result = await tcs.Task.DefaultTimeout(); + + Logger.LogInformation("Received result from disposing resolver."); Assert.AreEqual(StatusCode.Unavailable, result.Status.StatusCode); Assert.AreEqual("Error getting DNS hosts for address 'localhost'. TaskCanceledException: A task was canceled.", result.Status.Detail); Assert.AreEqual("A task was canceled.", result.Status.DebugException!.Message); diff --git a/test/FunctionalTests/Client/UnaryTests.cs b/test/FunctionalTests/Client/UnaryTests.cs index b0638a7ec..cc243b621 100644 --- a/test/FunctionalTests/Client/UnaryTests.cs +++ b/test/FunctionalTests/Client/UnaryTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // diff --git a/test/FunctionalTests/Infrastructure/RequireHttp3Attribute.cs b/test/FunctionalTests/Infrastructure/RequireHttp3Attribute.cs index cf0925eb1..17562ee18 100644 --- a/test/FunctionalTests/Infrastructure/RequireHttp3Attribute.cs +++ b/test/FunctionalTests/Infrastructure/RequireHttp3Attribute.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -16,6 +16,7 @@ #endregion +using System.Diagnostics.CodeAnalysis; using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; @@ -41,7 +42,7 @@ public void ApplyToTest(NUnit.Framework.Internal.Test test) test.Properties.Set(PropertyNames.SkipReason, message!); } - public static bool IsSupported(out string? message) + public static bool IsSupported([NotNullWhen(false)] out string? message) { var osVersion = Environment.OSVersion; if (osVersion.Platform == PlatformID.Win32NT && diff --git a/test/Grpc.Core.Api.Tests/Grpc.Core.Api.Tests.csproj b/test/Grpc.Core.Api.Tests/Grpc.Core.Api.Tests.csproj index 8d640559e..d0c171e5b 100755 --- a/test/Grpc.Core.Api.Tests/Grpc.Core.Api.Tests.csproj +++ b/test/Grpc.Core.Api.Tests/Grpc.Core.Api.Tests.csproj @@ -1,6 +1,6 @@ - net462;netcoreapp3.1 + net462;net6.0 true true diff --git a/test/Grpc.Core.Api.Tests/RpcExceptionTest.cs b/test/Grpc.Core.Api.Tests/RpcExceptionTest.cs index 3c8a4abb7..1989b3062 100644 --- a/test/Grpc.Core.Api.Tests/RpcExceptionTest.cs +++ b/test/Grpc.Core.Api.Tests/RpcExceptionTest.cs @@ -48,7 +48,7 @@ public void DefaultMessageDoesntContainDebugExceptionStacktrace() var ex = new RpcException(new Status(StatusCode.Internal, "abc", someExceptionWithStacktrace)); // Check debug exceptions's message is contained. StringAssert.Contains(someExceptionWithStacktrace.Message, ex.Message); - StringAssert.Contains(someExceptionWithStacktrace.GetType().FullName, ex.Message); + StringAssert.Contains(someExceptionWithStacktrace.GetType().FullName!, ex.Message); // If name of the current method is not in the message, it probably doesn't contain the stack trace. StringAssert.DoesNotContain(nameof(DefaultMessageDoesntContainDebugExceptionStacktrace), ex.Message); } diff --git a/test/Grpc.Core.Api.Tests/VersionInfoTest.cs b/test/Grpc.Core.Api.Tests/VersionInfoTest.cs index fe703e5dd..c2b9364ad 100644 --- a/test/Grpc.Core.Api.Tests/VersionInfoTest.cs +++ b/test/Grpc.Core.Api.Tests/VersionInfoTest.cs @@ -32,12 +32,12 @@ public void VersionInfoMatchesAssemblyProperties() var assemblyVersion = assembly!.GetName()!.Version!.ToString()!; Assert.AreEqual(VersionInfo.CurrentAssemblyVersion, assemblyVersion); - string assemblyFileVersion = FileVersionInfo.GetVersionInfo(assembly.Location)!.FileVersion; + string assemblyFileVersion = FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion!; string assemblyFileVersionFromAttribute = assembly.GetCustomAttribute()!.Version; Assert.AreEqual(VersionInfo.CurrentAssemblyFileVersion, assemblyFileVersion); Assert.AreEqual(VersionInfo.CurrentAssemblyFileVersion, assemblyFileVersionFromAttribute); - string productVersion = FileVersionInfo.GetVersionInfo(assembly.Location)!.ProductVersion; + string productVersion = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion!; string informationalVersionFromAttribute = assembly.GetCustomAttribute()!.InformationalVersion; Assert.AreEqual(productVersion, informationalVersionFromAttribute); // grpc-dotnet appends commit SHA to the product version (e.g. "2.45.0-dev+e30038495bd26b812b6684049353c045d1049d3c") diff --git a/test/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/test/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj index 8459bec05..37558de8e 100755 --- a/test/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj +++ b/test/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj @@ -1,6 +1,6 @@ - net462;netcoreapp3.1 + net462;net6.0 true diff --git a/test/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj b/test/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj index 365b569f2..d4085e615 100755 --- a/test/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj +++ b/test/Grpc.Reflection.Tests/Grpc.Reflection.Tests.csproj @@ -1,6 +1,6 @@ - net462;netcoreapp3.1 + net462;net6.0 true diff --git a/test/Grpc.Reflection.Tests/SymbolRegistryTest.cs b/test/Grpc.Reflection.Tests/SymbolRegistryTest.cs index 6dc426c72..eb5d55847 100644 --- a/test/Grpc.Reflection.Tests/SymbolRegistryTest.cs +++ b/test/Grpc.Reflection.Tests/SymbolRegistryTest.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2015 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,6 @@ using Grpc.Reflection.V1Alpha; using NUnit.Framework; - namespace Grpc.Reflection.Tests; /// diff --git a/test/dotnet-grpc.Tests/AddFileCommandTests.cs b/test/dotnet-grpc.Tests/AddFileCommandTests.cs index eb75e9d98..9f9d07b2b 100644 --- a/test/dotnet-grpc.Tests/AddFileCommandTests.cs +++ b/test/dotnet-grpc.Tests/AddFileCommandTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -44,7 +44,7 @@ public async Task Commandline_AddFileCommand_AddsPackagesAndReferences() var result = await parser.InvokeAsync($"add-file -p {tempDir} -s Server --access Internal -i ImportDir {Path.Combine("Proto", "*.proto")}", testConsole); // Assert - Assert.AreEqual(0, result, testConsole.Error.ToString()); + Assert.AreEqual(0, result, testConsole.Error.ToString()!); var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.Single(p => p.DirectoryPath == tempDir); project.ReevaluateIfNecessary(); @@ -53,7 +53,6 @@ public async Task Commandline_AddFileCommand_AddsPackagesAndReferences() Assert.AreEqual(1, packageRefs.Count); Assert.NotNull(packageRefs.SingleOrDefault(r => r.UnevaluatedInclude == "Grpc.AspNetCore" && !r.HasMetadata(CommandBase.PrivateAssetsElement))); - var protoRefs = project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(2, protoRefs.Count); Assert.NotNull(protoRefs.SingleOrDefault(r => r.UnevaluatedInclude == "Proto\\a.proto")); diff --git a/test/dotnet-grpc.Tests/AddUrlCommandTests.cs b/test/dotnet-grpc.Tests/AddUrlCommandTests.cs index 1252c9489..520eb326c 100644 --- a/test/dotnet-grpc.Tests/AddUrlCommandTests.cs +++ b/test/dotnet-grpc.Tests/AddUrlCommandTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -46,7 +46,7 @@ public async Task Commandline_AddUrlCommand_AddsPackagesAndReferences() var result = await parser.InvokeAsync($"add-url -p {tempDir} -s Server --access Internal -i ImportDir -o {Path.Combine("Proto", "c.proto")} {SourceUrl}", testConsole); // Assert - Assert.AreEqual(0, result, testConsole.Error.ToString()); + Assert.AreEqual(0, result, testConsole.Error.ToString()!); var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.Single(p => p.DirectoryPath == tempDir); project.ReevaluateIfNecessary(); diff --git a/test/dotnet-grpc.Tests/ListCommandTests.cs b/test/dotnet-grpc.Tests/ListCommandTests.cs index 8afcae20f..52ab6bfe6 100644 --- a/test/dotnet-grpc.Tests/ListCommandTests.cs +++ b/test/dotnet-grpc.Tests/ListCommandTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -44,7 +44,7 @@ public async Task Commandline_List_ListsReferences() var result = await parser.InvokeAsync($"list -p {tempDir}", testConsole); // Assert - Assert.AreEqual(0, result, testConsole.Error.ToString()); + Assert.AreEqual(0, result, testConsole.Error.ToString()!); var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.Single(p => p.DirectoryPath == tempDir); project.ReevaluateIfNecessary(); diff --git a/test/dotnet-grpc.Tests/RefreshCommandTests.cs b/test/dotnet-grpc.Tests/RefreshCommandTests.cs index ac75e6dbd..0d9bdfc14 100644 --- a/test/dotnet-grpc.Tests/RefreshCommandTests.cs +++ b/test/dotnet-grpc.Tests/RefreshCommandTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -46,7 +46,7 @@ public async Task Commandline_Refresh_RefreshesReferences(bool dryRun) var result = await parser.InvokeAsync($"refresh -p {tempDir} --dry-run {dryRun}", testConsole); // Assert - Assert.AreEqual(0, result, testConsole.Error.ToString()); + Assert.AreEqual(0, result, testConsole.Error.ToString()!); var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.Single(p => p.DirectoryPath == tempDir); project.ReevaluateIfNecessary(); diff --git a/test/dotnet-grpc.Tests/RemoveCommandTests.cs b/test/dotnet-grpc.Tests/RemoveCommandTests.cs index 60f01c8f0..889f7d010 100644 --- a/test/dotnet-grpc.Tests/RemoveCommandTests.cs +++ b/test/dotnet-grpc.Tests/RemoveCommandTests.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Copyright 2019 The gRPC Authors // @@ -43,7 +43,7 @@ public async Task Commandline_Remove_RemovesReferences() var result = await parser.InvokeAsync($"remove -p {tempDir} {Path.Combine("Proto", "a.proto")}", testConsole); // Assert - Assert.AreEqual(0, result, testConsole.Error.ToString()); + Assert.AreEqual(0, result, testConsole.Error.ToString()!); var project = ProjectCollection.GlobalProjectCollection.LoadedProjects.Single(p => p.DirectoryPath == tempDir); project.ReevaluateIfNecessary();