Skip to content

Commit ee87dc2

Browse files
[OTLP] Assert gauge and histogram
- Add a gauge and a histogram to the metrics test. - Rename variable. - Refactor use of `Assert.Single()`.
1 parent 6947c4f commit ee87dc2

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void TraceExportResultIsSuccess(
111111
bool forceFlush,
112112
string scheme)
113113
{
114-
using var handle = new ManualResetEvent(false);
114+
using var exported = new ManualResetEvent(false);
115115

116116
var exporterOptions = CreateExporterOptions(protocol, scheme, endpoint);
117117

@@ -142,7 +142,7 @@ public void TraceExportResultIsSuccess(
142142
{
143143
var result = otlpExporter.Export(batch);
144144
exportResults.Add(result);
145-
handle.Set();
145+
exported.Set();
146146
return result;
147147
},
148148
};
@@ -164,7 +164,7 @@ public void TraceExportResultIsSuccess(
164164
}
165165
else if (exporterOptions.ExportProcessorType == ExportProcessorType.Batch)
166166
{
167-
Assert.True(handle.WaitOne(ExportIntervalMilliseconds * 2));
167+
Assert.True(exported.WaitOne(ExportIntervalMilliseconds * 2));
168168
AssertExpectedTraces();
169169
}
170170
}
@@ -179,8 +179,8 @@ public void TraceExportResultIsSuccess(
179179

180180
void AssertExpectedTraces()
181181
{
182-
Assert.Single(exportResults);
183-
Assert.Equal(ExportResult.Success, exportResults[0]);
182+
var result = Assert.Single(exportResults);
183+
Assert.Equal(ExportResult.Success, result);
184184
}
185185
}
186186

@@ -194,7 +194,7 @@ public void MetricExportResultIsSuccess(
194194
bool forceFlush,
195195
string scheme)
196196
{
197-
using var handle = new ManualResetEvent(false);
197+
using var exported = new ManualResetEvent(false);
198198

199199
var exporterOptions = CreateExporterOptions(protocol, scheme, endpoint);
200200

@@ -223,7 +223,7 @@ public void MetricExportResultIsSuccess(
223223
{
224224
var result = otlpExporter.Export(batch);
225225
exportResults.Add(result);
226-
handle.Set();
226+
exported.Set();
227227
return result;
228228
},
229229
};
@@ -235,9 +235,14 @@ public void MetricExportResultIsSuccess(
235235
using var meter = new Meter(meterName);
236236

237237
var counter = meter.CreateCounter<int>("test_counter");
238-
239238
counter.Add(18);
240239

240+
var gauge = meter.CreateGauge<int>("test_gauge");
241+
gauge.Record(42);
242+
243+
var histogram = meter.CreateHistogram<int>("test_histogram");
244+
histogram.Record(100);
245+
241246
Assert.NotNull(delegatingExporter);
242247

243248
if (forceFlush)
@@ -247,7 +252,7 @@ public void MetricExportResultIsSuccess(
247252
}
248253
else if (!useManualExport)
249254
{
250-
Assert.True(handle.WaitOne(ExportIntervalMilliseconds * 2));
255+
Assert.True(exported.WaitOne(ExportIntervalMilliseconds * 2));
251256
AssertExpectedMetrics();
252257
}
253258
}
@@ -262,8 +267,8 @@ public void MetricExportResultIsSuccess(
262267

263268
void AssertExpectedMetrics()
264269
{
265-
Assert.Single(exportResults);
266-
Assert.Equal(ExportResult.Success, exportResults[0]);
270+
var result = Assert.Single(exportResults);
271+
Assert.Equal(ExportResult.Success, result);
267272
}
268273
}
269274

@@ -276,7 +281,7 @@ public void LogExportResultIsSuccess(
276281
ExportProcessorType exportProcessorType,
277282
string scheme)
278283
{
279-
using var handle = new ManualResetEvent(false);
284+
using var exported = new ManualResetEvent(false);
280285

281286
var exporterOptions = CreateExporterOptions(protocol, scheme, endpoint);
282287

@@ -310,7 +315,7 @@ public void LogExportResultIsSuccess(
310315
{
311316
var result = otlpExporter.Export(batch);
312317
exportResults.Add(result);
313-
handle.Set();
318+
exported.Set();
314319
return result;
315320
},
316321
};
@@ -324,7 +329,7 @@ public void LogExportResultIsSuccess(
324329
switch (processorOptions.ExportProcessorType)
325330
{
326331
case ExportProcessorType.Batch:
327-
Assert.True(handle.WaitOne(ExportIntervalMilliseconds * 2));
332+
Assert.True(exported.WaitOne(ExportIntervalMilliseconds * 2));
328333
break;
329334

330335
case ExportProcessorType.Simple:
@@ -334,8 +339,8 @@ public void LogExportResultIsSuccess(
334339
throw new NotSupportedException("Unexpected processor type encountered.");
335340
}
336341

337-
Assert.Single(exportResults);
338-
Assert.Equal(ExportResult.Success, exportResults[0]);
342+
var result = Assert.Single(exportResults);
343+
Assert.Equal(ExportResult.Success, result);
339344

340345
Assert.Empty(this.openTelemetryEventListener.Errors);
341346
Assert.Empty(this.openTelemetryEventListener.Warnings);

0 commit comments

Comments
 (0)