Skip to content

Commit 81117e6

Browse files
committed
Integration tests
1 parent 9153be8 commit 81117e6

File tree

6 files changed

+85
-15
lines changed

6 files changed

+85
-15
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using IntegrationTests.Helpers;
5+
using Xunit.Abstractions;
6+
7+
namespace IntegrationTests;
8+
9+
internal sealed class WcfCoreServerTestHelper : WcfServerTestHelperBase
10+
{
11+
private readonly string _packageVersion;
12+
13+
public WcfCoreServerTestHelper(ITestOutputHelper output, string packageVersion)
14+
: base("Wcf.Core", output, "TestApplication.Wcf.Core")
15+
{
16+
_packageVersion = packageVersion;
17+
}
18+
19+
internal override string ServerInstrumentationScopeName { get => "CoreWCF.Primitives"; }
20+
21+
internal override ProcessHelper RunWcfServer(MockSpansCollector collector)
22+
{
23+
var testApplicationPath = EnvironmentHelper.GetTestApplicationPath(_packageVersion, startupMode: TestAppStartupMode.Exe);
24+
25+
if (!File.Exists(testApplicationPath))
26+
{
27+
throw new Exception($"Unable to find executing assembly at {testApplicationPath}");
28+
}
29+
30+
SetExporter(collector);
31+
var process = InstrumentedProcessHelper.Start(testApplicationPath, null, EnvironmentHelper);
32+
return new ProcessHelper(process);
33+
}
34+
}

test/IntegrationTests/WcfDotNetTests.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,30 @@ public WcfDotNetTests(ITestOutputHelper output)
1414
{
1515
}
1616

17+
public static TheoryData<string, Func<ITestOutputHelper, WcfServerTestHelperBase>> GetData()
18+
{
19+
var theoryData = new TheoryData<string, Func<ITestOutputHelper, WcfServerTestHelperBase>>();
20+
21+
foreach (var version in LibraryVersion.WCFCoreClient)
22+
{
23+
theoryData.Add(version, output => new WcfServerTestHelper(output));
24+
25+
foreach (var wcfCoreServerVersion in LibraryVersion.WCFCoreServer)
26+
{
27+
theoryData.Add(version, output => new WcfCoreServerTestHelper(output, wcfCoreServerVersion));
28+
}
29+
}
30+
31+
return theoryData;
32+
}
33+
1734
[Trait("Category", "EndToEnd")]
1835
[Theory]
19-
[MemberData(nameof(LibraryVersion.WCFCoreClient), MemberType = typeof(LibraryVersion))]
20-
public async Task SubmitTraces(string clientPackageVersion)
36+
[MemberData(nameof(GetData))]
37+
public async Task SubmitTraces(string clientPackageVersion, Func<ITestOutputHelper, WcfServerTestHelperBase> wcfServerTestHelperFactory)
2138
{
2239
EnableBytecodeInstrumentation();
23-
await SubmitsTracesInternal(clientPackageVersion);
40+
await SubmitsTracesInternal(clientPackageVersion, wcfServerTestHelperFactory(Output));
2441
}
2542
}
2643

test/IntegrationTests/WcfNetFrameworkTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public WcfNetFrameworkTests(ITestOutputHelper output)
1919
[Trait("Category", "EndToEnd")]
2020
public async Task SubmitsTraces()
2121
{
22-
await SubmitsTracesInternal(string.Empty);
22+
await SubmitsTracesInternal(string.Empty, new WcfServerTestHelper(Output));
2323
}
2424

2525
[Fact]

test/IntegrationTests/WcfServerTestHelper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
namespace IntegrationTests;
88

9-
internal class WcfServerTestHelper : TestHelper
9+
internal sealed class WcfServerTestHelper : WcfServerTestHelperBase
1010
{
11-
private const string ServiceName = "TestApplication.Wcf.Server.NetFramework";
12-
1311
public WcfServerTestHelper(ITestOutputHelper output)
14-
: base("Wcf.Server.NetFramework", output)
12+
: base("Wcf.Server.NetFramework", output, "TestApplication.Wcf.Server.NetFramework")
1513
{
16-
SetEnvironmentVariable("OTEL_SERVICE_NAME", ServiceName);
1714
}
1815

19-
public ProcessHelper RunWcfServer(MockSpansCollector collector)
16+
internal override string ServerInstrumentationScopeName { get => "OpenTelemetry.Instrumentation.Wcf"; }
17+
18+
internal override ProcessHelper RunWcfServer(MockSpansCollector collector)
2019
{
2120
var baseBinDirectory = EnvironmentHelper.GetTestApplicationBaseBinDirectory();
2221
var exeFileName = $"{EnvironmentHelper.FullTestApplicationName}.exe";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using IntegrationTests.Helpers;
5+
using Xunit.Abstractions;
6+
7+
namespace IntegrationTests;
8+
9+
public abstract class WcfServerTestHelperBase : TestHelper
10+
{
11+
protected WcfServerTestHelperBase(string testApplicationName, ITestOutputHelper output, string serviceName)
12+
: base(testApplicationName, output)
13+
{
14+
SetEnvironmentVariable("OTEL_SERVICE_NAME", serviceName);
15+
}
16+
17+
internal abstract string ServerInstrumentationScopeName { get; }
18+
19+
internal abstract ProcessHelper RunWcfServer(MockSpansCollector collector);
20+
}

test/IntegrationTests/WcfTestsBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ public void Dispose()
4040
Output.WriteResult(_serverProcess);
4141
}
4242

43-
protected async Task SubmitsTracesInternal(string clientPackageVersion)
43+
protected async Task SubmitsTracesInternal(string clientPackageVersion, WcfServerTestHelperBase wcfServerTestHelperBase)
4444
{
4545
Assert.True(EnvironmentTools.IsWindowsAdministrator(), "This test requires Windows Administrator privileges.");
4646

4747
var collector = new MockSpansCollector(Output);
4848
SetExporter(collector);
4949

50-
var serverHelper = new WcfServerTestHelper(Output);
51-
_serverProcess = serverHelper.RunWcfServer(collector);
50+
_serverProcess = wcfServerTestHelperBase.RunWcfServer(collector);
51+
5252
await WaitForServer();
5353

5454
RunTestApplication(new TestSettings
5555
{
5656
PackageVersion = clientPackageVersion
5757
});
5858

59-
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == SpanKind.Server, "Server 1");
59+
collector.Expect(wcfServerTestHelperBase.ServerInstrumentationScopeName, span => span.Kind == SpanKind.Server, "Server 1");
6060
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == SpanKind.Client, "Client 1");
61-
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == SpanKind.Server, "Server 2");
61+
collector.Expect(wcfServerTestHelperBase.ServerInstrumentationScopeName, span => span.Kind == SpanKind.Server, "Server 2");
6262
collector.Expect("OpenTelemetry.Instrumentation.Wcf", span => span.Kind == SpanKind.Client, "Client 2");
6363

6464
collector.Expect($"TestApplication.{_testAppName}", span => span.Kind == SpanKind.Internal, "Custom parent");

0 commit comments

Comments
 (0)