Skip to content

Commit

Permalink
Chore: Resolve warnings for all tests (#1916)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrcventura authored Sep 15, 2023
1 parent f395476 commit 32c3b17
Show file tree
Hide file tree
Showing 18 changed files with 1,080 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public string Sync_FireAndForget(EventWaitHandle waitHandle)
{
var transactionName = UpdateTransactionName("SF");

Task.Run(() => AsyncMethod(DELAY_TIME, transactionName, waitHandle));
_ = Task.Run(() => AsyncMethod(DELAY_TIME, transactionName, waitHandle));

Thread.Sleep(SHORT_DELAY_TIME);

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@
<bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task Main(string[] args)
public static void CreatePidFile()
{
var pidFileNameAndPath = Path.Combine(Environment.GetEnvironmentVariable("NEWRELIC_LOG_DIRECTORY"), "containerizedapp.pid");
var pid = Process.GetCurrentProcess().Id;
var pid = Environment.ProcessId;
using var file = File.CreateText(pidFileNameAndPath);
file.WriteLine(pid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO.Pipes;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

namespace NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures
Expand Down Expand Up @@ -371,6 +372,8 @@ public virtual void Shutdown()
{
try
{
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));

//The test runner opens an event created by the app server and set it to signal the app server that the test has finished.
var remoteAppEvent = EventWaitHandle.OpenExisting(shutdownChannelName);
remoteAppEvent.Set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0


using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using NewRelic.Agent.IntegrationTestHelpers.RemoteServiceFixtures;

Expand All @@ -17,6 +19,7 @@ public ThreadProfileStressTestWithCollectorFixture() : base(new RemoteService(Ap

public void StartThreadStressScenario()
{
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
var expectedWaitHandle = $"thread_profile_stress_begin_{Port}";
var remoteAppEvent = EventWaitHandle.OpenExisting(expectedWaitHandle);
remoteAppEvent.Set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Runtime.CompilerServices;
using NewRelic.Api.Agent;
using System;
using System.Web.Http.Results;

namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MongoDB
{
Expand Down Expand Up @@ -530,6 +529,12 @@ public async Task AggregateToCollectionAsync()
}
#endif

// The Count and CountAsync methods are replaced and marked Obsolete in newer versions of the driver.
// We are continuing to test these methods until they are removed because of how the instrumentation
// for MongoDB was implemented.
#if !MONGODRIVER2_3
#pragma warning disable CS0618 // Type or member is obsolete
#endif
[LibraryMethod]
[Transaction]
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
Expand All @@ -551,8 +556,12 @@ public async Task<long> CountAsync()
var filter = Builders<CustomMongoDbEntity>.Filter.Eq("Name", "Fred Flintstone");
return await Collection.CountAsync(filter);
}
#if !MONGODRIVER2_3
// Restoring Obsolete warnings so that we can more easily identify instrumentation gaps
#pragma warning restore CS0618 // Type or member is obsolete
#endif

// CountDocuments{Async} did not exist in driver version 2.3 which is bound to net462 in MultiFunctionApplicationHelpers.csproj
// CountDocuments{Async} did not exist in driver version 2.3 which is bound to net462 in MultiFunctionApplicationHelpers.csproj
#if !MONGODRIVER2_3
[LibraryMethod]
[Transaction]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ public async Task<string> RestSharpClientTaskCancelled(int port)

try
{
var client = new RestClient($"http://{myHost}:{myPort}");
client.Timeout = 1;
var response = await client.ExecuteTaskAsync(new RestRequest(endpoint + "Get/" + id));
var client = new RestClient($"http://{myHost}:{myPort}")
{
Timeout = 1
};
var response = await ExecuteAsync(client, new RestRequest(endpoint + "Get/" + id));
}
catch (Exception)
{
Expand All @@ -190,37 +192,55 @@ public async Task<string> RestSharpClientTaskCancelled(int port)

#region Helpers

private Dictionary<string, IRestRequest> GetRequests(string endpoint, int id)
private static Dictionary<string, IRestRequest> GetRequests(string endpoint, int id)
{
var requests = new Dictionary<string, IRestRequest>();
requests.Add("GET", new RestRequest(endpoint + "Get/" + id));
requests.Add("PUT", new RestRequest(endpoint + "Put/" + id, Method.PUT).AddJsonBody(new { CommonName = "Painted Bunting", BandingCode = "PABU" }));
requests.Add("DELETE", new RestRequest(endpoint + "Delete/" + id, Method.DELETE));
requests.Add("POST", new RestRequest(endpoint + "Post/", Method.POST).AddJsonBody(new { CommonName = "Painted Bunting", BandingCode = "PABU" }));
var requests = new Dictionary<string, IRestRequest>
{
{ "GET", new RestRequest(endpoint + "Get/" + id) },
{ "PUT", new RestRequest(endpoint + "Put/" + id, Method.PUT).AddJsonBody(new { CommonName = "Painted Bunting", BandingCode = "PABU" }) },
{ "DELETE", new RestRequest(endpoint + "Delete/" + id, Method.DELETE) },
{ "POST", new RestRequest(endpoint + "Post/", Method.POST).AddJsonBody(new { CommonName = "Painted Bunting", BandingCode = "PABU" }) }
};
return requests;
}

private Task<IRestResponse<T>> ExecuteAsyncGeneric<T>(RestClient client, IRestRequest request, CancellationTokenSource cancellationTokenSource = null)
private static Task<IRestResponse<T>> ExecuteAsyncGeneric<T>(RestClient client, IRestRequest request, CancellationTokenSource cancellationTokenSource = null)
{
if (cancellationTokenSource == null)
{
#if NET471
return client.ExecuteAsync<T>(request);
#else
return client.ExecuteTaskAsync<T>(request);
#endif
}

#if NET471
return client.ExecuteAsync<T>(request, cancellationTokenSource.Token);
#else
return client.ExecuteTaskAsync<T>(request, cancellationTokenSource.Token);
#endif
}

private Task<IRestResponse> ExecuteAsync(RestClient client, IRestRequest request, CancellationTokenSource cancellationTokenSource = null)
private static Task<IRestResponse> ExecuteAsync(RestClient client, IRestRequest request, CancellationTokenSource cancellationTokenSource = null)
{
if (cancellationTokenSource == null)
{
#if NET471
return client.ExecuteAsync(request);
#else
return client.ExecuteTaskAsync(request);
#endif
}

#if NET471
return client.ExecuteAsync(request, cancellationTokenSource.Token);
#else
return client.ExecuteTaskAsync(request, cancellationTokenSource.Token);
#endif
}

#endregion
#endregion

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace MultiFunctionApplicationHelpers.NetStandardLibraries.RestSharp
[Library]
public class RestSharpService
{
private readonly HttpClient _client = new HttpClient();
private OwinService _owinService;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void DoSomeWork()
db.SetRemove("myset", "cool");
db.SetPop("myset");

db.Publish("mychannel", "cable"); // 31
db.Publish(new RedisChannel("mychannel", RedisChannel.PatternMode.Literal), "cable"); // 31
}

ConsoleMFLogger.Info("All done!");
Expand Down Expand Up @@ -114,7 +114,7 @@ public async Task DoSomeWorkAsync()
await db.SetRemoveAsync("myset", "cool");
await db.SetPopAsync("myset");

await db.PublishAsync("mychannel", "cable"); // 31
await db.PublishAsync(new RedisChannel("mychannel", RedisChannel.PatternMode.Literal), "cable"); // 31
}

ConsoleMFLogger.Info("All done!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
</ItemGroup>

<ItemGroup>
<None Include="Properties\PublishProfiles\LocalDeploy.pubxml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -79,9 +79,6 @@
<PackageReference Include="Microsoft.AspNet.Razor">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.Razor">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebPages">
<Version>3.2.0</Version>
</PackageReference>
Expand Down Expand Up @@ -183,4 +180,4 @@
</ReferencePath>
</ItemGroup>
</Target>
</Project>
</Project>
Loading

0 comments on commit 32c3b17

Please sign in to comment.