Skip to content

Commit 0db06bc

Browse files
committed
remove external service usage from nuget tests
1 parent e7659c5 commit 0db06bc

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

test/IntegrationTests/Helpers/TestHttpServer.NetFramework.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public TestHttpServer(ITestOutputHelper output, Action<HttpListenerContext> requ
3737
/// </summary>
3838
public int Port { get; }
3939

40+
public static TestHttpServer CreateDefaultTestServer(ITestOutputHelper output)
41+
{
42+
return new TestHttpServer(
43+
output,
44+
context =>
45+
{
46+
context.Response.StatusCode = 200;
47+
context.Response.Close();
48+
},
49+
"localhost",
50+
"/test/");
51+
}
52+
4053
public void Dispose()
4154
{
4255
WriteOutput($"Shutting down");

test/NuGetPackagesTests/NugetSampleTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ private void InstrumentDll(string appDir)
9494
{
9595
RunAndAssertHttpSpans(() =>
9696
{
97+
using var testServer = TestHttpServer.CreateDefaultTestServer(Output);
9798
var dllName = EnvironmentHelper.FullTestApplicationName.EndsWith(".exe")
9899
? EnvironmentHelper.FullTestApplicationName.Replace(".exe", ".dll")
99100
: EnvironmentHelper.FullTestApplicationName + ".dll";
100101
var dllPath = Path.Combine(appDir, dllName);
101-
RunInstrumentationTarget($"dotnet {dllPath}", appDir);
102+
RunInstrumentationTarget($"dotnet {dllPath} --test-server-port {testServer.Port}", appDir);
102103
});
103104
}
104105
#endif
@@ -107,9 +108,10 @@ private void InstrumentExecutable(string appDir)
107108
{
108109
RunAndAssertHttpSpans(() =>
109110
{
111+
using var testServer = TestHttpServer.CreateDefaultTestServer(Output);
110112
var instrumentationTarget = Path.Combine(appDir, EnvironmentHelper.FullTestApplicationName);
111113
instrumentationTarget = EnvironmentTools.IsWindows() ? instrumentationTarget + ".exe" : instrumentationTarget;
112-
RunInstrumentationTarget(instrumentationTarget, appDir);
114+
RunInstrumentationTarget($"{instrumentationTarget} --test-server-port {testServer.Port}", appDir);
113115
});
114116
}
115117

@@ -142,7 +144,7 @@ private void RunInstrumentationTarget(string instrumentationTarget, string appDi
142144

143145
private void RunAndAssertHttpSpans(Action appLauncherAction)
144146
{
145-
var collector = new MockSpansCollector(Output);
147+
using var collector = new MockSpansCollector(Output);
146148
SetExporter(collector);
147149

148150
#if NETFRAMEWORK

test/test-applications/integrations/TestApplication.CustomSdk/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static async Task Main(string[] args)
2727
{
2828
if (args.Length != 4)
2929
{
30-
throw new InvalidOperationException("Usage: TestApplication.CustomSdk.exe --redis-port <redis-port> --test-server-port <test-server-port>");
30+
throw new InvalidOperationException("Missing arguments. Provide redis port with --redis-port <redis-port> and test server port with --test-server-port <test-server-port>.");
3131
}
3232

3333
ConsoleHelper.WriteSplashScreen(args);

test/test-applications/nuget-packages/TestApplication.NugetSample/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414
// limitations under the License.
1515
// </copyright>
1616

17+
18+
using System.Globalization;
1719
#if NETFRAMEWORK
1820
using System.Net.Http;
1921
#endif
2022

2123
using var httpClient = new HttpClient();
2224
httpClient.Timeout = TimeSpan.FromSeconds(10);
25+
if (args.Length != 2)
26+
{
27+
throw new InvalidOperationException("Missing arguments. Provide test server port with --test-server-port <test-server-port>");
28+
}
2329
try
2430
{
25-
var response = await httpClient.GetAsync("http://example.com");
31+
var testServerPort = int.Parse(args[1], CultureInfo.InvariantCulture);
32+
var response = await httpClient.GetAsync($"http://localhost:{testServerPort}/test/");
2633
Console.WriteLine(response.StatusCode);
2734
}
2835
catch (Exception e)

0 commit comments

Comments
 (0)