Skip to content

Commit

Permalink
Updates RestSharp testing to use ConsoleMF app and expands tested ver…
Browse files Browse the repository at this point in the history
…sions (#1286)

* Creates RestSharp library and updates tests to use it

* Clears up merge issues from add net7.0 and net481
  • Loading branch information
jaffinito authored Oct 26, 2022
1 parent 3ab9337 commit 08aef89
Show file tree
Hide file tree
Showing 10 changed files with 629 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public void GetHttpClientTaskCancelled()
var address = $"http://{DestinationServerName}:{Port}/Default/HttpClientTaskCancelled";
DownloadStringAndAssertEqual(address, "Worked");
}
public void GetRestSharpSyncClient(string method, bool generic)
{
var address = $"http://{DestinationServerName}:{Port}/RestSharp/SyncClient?method={method}&generic={generic}";
DownloadStringAndAssertEqual(address, "Worked");
}
public void GetRestSharpAsyncAwaitClient(string method, bool generic, bool cancelable)
{
var address = $"http://{DestinationServerName}:{Port}/RestSharp/AsyncAwaitClient?method={method}&generic={generic}&cancelable={cancelable}";
DownloadStringAndAssertEqual(address, "Worked");
}

public HttpResponseHeaders GetRestSharpAsyncAwaitClientWithHeaders(string method, bool generic, bool cancelable)
{
Expand All @@ -74,12 +64,6 @@ public HttpResponseHeaders GetRestSharpAsyncAwaitClientWithHeaders(string method

}

public void GetRestSharpTaskResultClient(string method, bool generic, bool cancelable)
{
var address = $"http://{DestinationServerName}:{Port}/RestSharp/TaskResultClient?method={method}&generic={generic}&cancelable={cancelable}";
DownloadStringAndAssertEqual(address, "Worked");
}

public HttpResponseHeaders GetRestSharpTaskResultClientWithHeaders(string method, bool generic, bool cancelable)
{
var address = $"http://{DestinationServerName}:{Port}/RestSharp/TaskResultClient?method={method}&generic={generic}&cancelable={cancelable}";
Expand All @@ -103,12 +87,6 @@ public HttpResponseHeaders GetRestSharpTaskResultClientWithHeaders(string method

}

public void GetRestSharpClientTaskCancelled()
{
var address = $"http://{DestinationServerName}:{Port}/RestSharp/RestSharpClientTaskCancelled";
DownloadStringAndAssertEqual(address, "Worked");
}

public void Get404(string Path = "DoesNotExist")
{
var address = $"http://{DestinationServerName}:{Port}/{Path}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,67 @@
using NewRelic.Testing.Assertions;
using Xunit;
using Xunit.Abstractions;
using System;
using MultiFunctionApplicationHelpers;

namespace NewRelic.Agent.IntegrationTests.RestSharp
{
[NetFrameworkTest]
public class RestSharpInstrumentationAsyncAwaitCAT : NewRelicIntegrationTest<RemoteServiceFixtures.BasicMvcApplicationTestFixture>
public abstract class RestSharpInstrumentationAsyncAwaitCATBase<TFixture> : NewRelicIntegrationTest<TFixture>
where TFixture : ConsoleDynamicMethodFixture
{
private readonly RemoteServiceFixtures.BasicMvcApplicationTestFixture _fixture;
private readonly TFixture _fixture;

public RestSharpInstrumentationAsyncAwaitCAT(RemoteServiceFixtures.BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) : base(fixture)
public RestSharpInstrumentationAsyncAwaitCATBase(TFixture fixture, ITestOutputHelper output) : base(fixture)
{
_fixture = fixture;
_fixture.SetTimeout(TimeSpan.FromMinutes(2));
_fixture.TestLogger = output;
_fixture.Actions(

_fixture.AddCommand($"RestSharpService StartService {_fixture.RemoteApplication.Port}");
_fixture.AddCommand($"RestSharpExerciser AsyncAwaitClient {_fixture.RemoteApplication.Port} GET true true");
_fixture.AddCommand($"RestSharpExerciser AsyncAwaitClient {_fixture.RemoteApplication.Port} PUT false false");
_fixture.AddCommand($"RestSharpExerciser AsyncAwaitClient {_fixture.RemoteApplication.Port} POST false false");
_fixture.AddCommand($"RestSharpExerciser AsyncAwaitClient {_fixture.RemoteApplication.Port} DELETE true true");
_fixture.AddCommand("RestSharpService StopService");

_fixture.AddActions
(
setupConfiguration: () =>
{
var configPath = fixture.DestinationNewRelicConfigFilePath;
var configModifier = new NewRelicConfigModifier(configPath);

configModifier.EnableCat();
configModifier.ForceTransactionTraces();
},
exerciseApplication: () =>
{
_fixture.GetRestSharpAsyncAwaitClient(method: "GET", generic: true, cancelable: true);
_fixture.GetRestSharpAsyncAwaitClient(method: "PUT", generic: false, cancelable: false);
_fixture.GetRestSharpAsyncAwaitClient(method: "POST", generic: false, cancelable: false);
_fixture.GetRestSharpAsyncAwaitClient(method: "DELETE", generic: true, cancelable: true);
}
);

_fixture.Initialize();
}

[Fact]
public void Test()
{
var myHostname = _fixture.DestinationServerName; // This is needed because we are making "external" calls to ourself to test RestSharp
var crossProcessId = _fixture.AgentLog.GetCrossProcessId();
var callerTransactionName = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.RestSharp.RestSharpExerciser/AsyncAwaitClient";

var expectedMetrics = new List<Assertions.ExpectedMetric>
{
new Assertions.ExpectedMetric { metricName = "External/all", callCount = 4 },
new Assertions.ExpectedMetric { metricName = "External/allWeb", callCount = 4 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/GET", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/PUT", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/POST", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/DELETE", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", metricScope = @"WebTransaction/MVC/RestSharpController/AsyncAwaitClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Put", metricScope = @"WebTransaction/MVC/RestSharpController/AsyncAwaitClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Post", metricScope = @"WebTransaction/MVC/RestSharpController/AsyncAwaitClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Delete", metricScope = @"WebTransaction/MVC/RestSharpController/AsyncAwaitClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/GET", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/PUT", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/POST", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/DELETE", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Put", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Post", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Delete", metricScope = callerTransactionName, callCount = 1 },
};

var metrics = _fixture.AgentLog.GetMetrics().ToList();

var transactionSample = _fixture.AgentLog.GetTransactionSamples()
.Where(sample => sample.Path == @"WebTransaction/MVC/RestSharpController/AsyncAwaitClient" || sample.Path == @"WebTransaction/WebAPI/RestAPI/Get")
.Where(sample => sample.Path == callerTransactionName || sample.Path == @"WebTransaction/WebAPI/RestAPI/Get")
.FirstOrDefault();

Assert.NotNull(transactionSample);
Expand All @@ -84,4 +89,40 @@ public void Test()
Assert.Null(wrapperError);
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationAsyncAwaitCATFWLatest : RestSharpInstrumentationAsyncAwaitCATBase<ConsoleDynamicMethodFixtureFWLatest>
{
public RestSharpInstrumentationAsyncAwaitCATFWLatest(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationAsyncAwaitCATFW48 : RestSharpInstrumentationAsyncAwaitCATBase<ConsoleDynamicMethodFixtureFW48>
{
public RestSharpInstrumentationAsyncAwaitCATFW48(ConsoleDynamicMethodFixtureFW48 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationAsyncAwaitCATFW471 : RestSharpInstrumentationAsyncAwaitCATBase<ConsoleDynamicMethodFixtureFW471>
{
public RestSharpInstrumentationAsyncAwaitCATFW471(ConsoleDynamicMethodFixtureFW471 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationAsyncAwaitCATFW462 : RestSharpInstrumentationAsyncAwaitCATBase<ConsoleDynamicMethodFixtureFW462>
{
public RestSharpInstrumentationAsyncAwaitCATFW462(ConsoleDynamicMethodFixtureFW462 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NewRelic.Agent.IntegrationTestHelpers;
using NewRelic.Testing.Assertions;
using Xunit;
using Xunit.Abstractions;
using System;
using MultiFunctionApplicationHelpers;

namespace NewRelic.Agent.IntegrationTests.RestSharp
{
[NetFrameworkTest]
public class RestSharpInstrumentationCAT : NewRelicIntegrationTest<RemoteServiceFixtures.BasicMvcApplicationTestFixture>
public abstract class RestSharpInstrumentationCATBase<TFixture> : NewRelicIntegrationTest<TFixture>
where TFixture : ConsoleDynamicMethodFixture
{
private readonly RemoteServiceFixtures.BasicMvcApplicationTestFixture _fixture;
private readonly TFixture _fixture;

public RestSharpInstrumentationCAT(RemoteServiceFixtures.BasicMvcApplicationTestFixture fixture, ITestOutputHelper output) : base(fixture)
public RestSharpInstrumentationCATBase(TFixture fixture, ITestOutputHelper output) : base(fixture)
{
_fixture = fixture;
_fixture.SetTimeout(TimeSpan.FromMinutes(2));
_fixture.TestLogger = output;
_fixture.Actions(

_fixture.AddCommand($"RestSharpService StartService {_fixture.RemoteApplication.Port}");
_fixture.AddCommand($"RestSharpExerciser SyncClient {_fixture.RemoteApplication.Port} GET false");
_fixture.AddCommand($"RestSharpExerciser SyncClient {_fixture.RemoteApplication.Port} PUT false");
_fixture.AddCommand($"RestSharpExerciser SyncClient {_fixture.RemoteApplication.Port} POST false");
_fixture.AddCommand($"RestSharpExerciser SyncClient {_fixture.RemoteApplication.Port} DELETE false");
_fixture.AddCommand($"RestSharpExerciser RestSharpClientTaskCancelled {_fixture.RemoteApplication.Port}");
_fixture.AddCommand("RestSharpService StopService");

_fixture.AddActions
(
setupConfiguration: () =>
{
var configPath = fixture.DestinationNewRelicConfigFilePath;
Expand All @@ -30,48 +42,37 @@ public RestSharpInstrumentationCAT(RemoteServiceFixtures.BasicMvcApplicationTest
configModifier.SetLogLevel("finest");
configModifier.EnableCat();
configModifier.ForceTransactionTraces();
},
exerciseApplication: () =>
{
_fixture.GetRestSharpSyncClient(method: "GET", generic: false);
_fixture.GetRestSharpSyncClient(method: "PUT", generic: false);
_fixture.GetRestSharpSyncClient(method: "POST", generic: false);
_fixture.GetRestSharpSyncClient(method: "DELETE", generic: false);
_fixture.GetRestSharpClientTaskCancelled();

//Adding some time for metrics to be fully generated.
Thread.Sleep(3000);
}
);

_fixture.Initialize();
}

[Fact]
public void Test()
{
var myHostname = _fixture.DestinationServerName; // This is needed because we are making "external" calls to ourself to test RestSharp
var crossProcessId = _fixture.AgentLog.GetCrossProcessId();
var callerTransactionName = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.RestSharp.RestSharpExerciser/SyncClient";
var cancelledTrasnsactionName = "OtherTransaction/Custom/MultiFunctionApplicationHelpers.NetStandardLibraries.RestSharp.RestSharpExerciser/RestSharpClientTaskCancelled";

var expectedMetrics = new List<Assertions.ExpectedMetric>
{

new Assertions.ExpectedMetric { metricName = "External/all", callCount = 5 },
new Assertions.ExpectedMetric { metricName = "External/allWeb", callCount = 5 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/GET", callCount = 2 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/PUT", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/POST", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/DELETE", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/{myHostname}/Stream/GET", metricScope = @"WebTransaction/MVC/RestSharpController/RestSharpClientTaskCancelled", callCount = 1},
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", metricScope = @"WebTransaction/MVC/RestSharpController/SyncClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Put", metricScope = @"WebTransaction/MVC/RestSharpController/SyncClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Post", metricScope = @"WebTransaction/MVC/RestSharpController/SyncClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/{myHostname}/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Delete", metricScope = @"WebTransaction/MVC/RestSharpController/SyncClient", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/GET", callCount = 2 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/PUT", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/POST", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/DELETE", callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"External/localhost/Stream/GET", metricScope = cancelledTrasnsactionName, callCount = 1},
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Get", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Put", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Post", metricScope = callerTransactionName, callCount = 1 },
new Assertions.ExpectedMetric { metricName = $"ExternalTransaction/localhost/{crossProcessId}/WebTransaction/WebAPI/RestAPI/Delete", metricScope = callerTransactionName, callCount = 1 },
};

var metrics = _fixture.AgentLog.GetMetrics().ToList();

var transactionSample = _fixture.AgentLog.GetTransactionSamples()
.Where(sample => sample.Path == @"WebTransaction/MVC/RestSharpController/SyncClient" || sample.Path == @"WebTransaction/WebAPI/RestAPI/Get" || sample.Path == @"WebTransaction/MVC/RestSharpController/RestSharpClientTaskCancelled")
.Where(sample => sample.Path == callerTransactionName || sample.Path == @"WebTransaction/WebAPI/RestAPI/Get" || sample.Path == cancelledTrasnsactionName)
.FirstOrDefault();

Assert.NotNull(transactionSample);
Expand All @@ -92,4 +93,40 @@ public void Test()
Assert.Null(wrapperError);
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationCATFWLatest : RestSharpInstrumentationCATBase<ConsoleDynamicMethodFixtureFWLatest>
{
public RestSharpInstrumentationCATFWLatest(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationCATFW48 : RestSharpInstrumentationCATBase<ConsoleDynamicMethodFixtureFW48>
{
public RestSharpInstrumentationCATFW48(ConsoleDynamicMethodFixtureFW48 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationCATFW471 : RestSharpInstrumentationCATBase<ConsoleDynamicMethodFixtureFW471>
{
public RestSharpInstrumentationCATFW471(ConsoleDynamicMethodFixtureFW471 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}

[NetFrameworkTest]
public class RestSharpInstrumentationCATFW462 : RestSharpInstrumentationCATBase<ConsoleDynamicMethodFixtureFW462>
{
public RestSharpInstrumentationCATFW462(ConsoleDynamicMethodFixtureFW462 fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
}
}
Loading

0 comments on commit 08aef89

Please sign in to comment.