-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathWorkerTests.cs
45 lines (32 loc) · 1.15 KB
/
WorkerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Logs.V1;
using Xunit.Abstractions;
namespace IntegrationTests;
public class WorkerTests : TestHelper
{
public WorkerTests(ITestOutputHelper output)
: base("Worker", output)
{
}
[Fact]
public async Task SubmitsLogsWithoutDuplicates()
{
using var collector = new MockLogsCollector(Output);
SetExporter(collector);
collector.ExpectCollected(ValidateSingleAppLogRecord, "App log record should be exported once.");
SetEnvironmentVariable("OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE", "true");
EnableBytecodeInstrumentation();
RunTestApplication();
// wait for fixed amount of time for logs to be collected before asserting
await Task.Delay(TimeSpan.FromSeconds(10));
collector.AssertCollected();
}
private static bool ValidateSingleAppLogRecord(IEnumerable<LogRecord> records)
{
return records.Count(lr => Convert.ToString(lr.Body) == "{ \"stringValue\": \"Worker running.\" }") == 1;
}
}
#endif