Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter.Geneva] Add test case for multithreading scenarios #549

Merged
merged 5 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using Xunit;
Expand Down Expand Up @@ -871,6 +872,23 @@ public void SuccessfulExportOnLinux()

// Validation
Assert.Equal(messagePackDataSize, receivedDataSize);

logRecordList.Clear();

// Emit log on a different thread to test for multithreading scenarios
var thread = new Thread(() =>
{
logger.LogInformation("Hello from another thread {food} {price}.", "artichoke", 3.99);
});
thread.Start();
thread.Join();

// logRecordList should have a singleLogRecord entry after the logger.LogInformation call
Assert.Single(logRecordList);

messagePackDataSize = exporter.SerializeLogRecord(logRecordList[0]);
receivedDataSize = serverSocket.Receive(receivedData);
Assert.Equal(messagePackDataSize, receivedDataSize);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Trace;
using Xunit;

Expand Down Expand Up @@ -414,6 +415,7 @@ public void GenevaTraceExporter_Success_Linux()
})
.Build();
using Socket serverSocket = server.Accept();
serverSocket.ReceiveTimeout = 10000;

// Create a test exporter to get MessagePack byte data for validation of the data received via Socket.
var exporter = new GenevaTraceExporter(new GenevaExporterOptions
Expand All @@ -429,7 +431,8 @@ public void GenevaTraceExporter_Success_Linux()

// Emit trace and grab a copy of internal buffer for validation.
var source = new ActivitySource(sourceName);
int messagePackDataSize;
int messagePackDataSize = 0;

using (var activity = source.StartActivity("Foo", ActivityKind.Internal))
{
messagePackDataSize = exporter.SerializeActivity(activity);
Expand All @@ -441,6 +444,20 @@ public void GenevaTraceExporter_Success_Linux()

// Validation
Assert.Equal(messagePackDataSize, receivedDataSize);

// Create activity on a different thread to test for multithreading scenarios
var thread = new Thread(() =>
{
using (var activity = source.StartActivity("ActivityFromAnotherThread", ActivityKind.Internal))
{
messagePackDataSize = exporter.SerializeActivity(activity);
}
});
thread.Start();
thread.Join();

receivedDataSize = serverSocket.Receive(receivedData);
Assert.Equal(messagePackDataSize, receivedDataSize);
}
catch (Exception)
{
Expand Down