Skip to content

Commit 9185f37

Browse files
authored
Merge pull request #59 from mathworks/metrics_merge
Add shutdown tests to ttrace_sdk
2 parents 10b014c + 9222d37 commit 9185f37

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

test/ttrace_sdk.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,84 @@ function testCustomResource(testCase)
209209
verifyEqual(testCase, results.resourceSpans.resource.attributes(idx).value.doubleValue, customvalues(i));
210210
end
211211
end
212+
213+
function testShutdown(testCase)
214+
% testShutdown: shutdown method should stop exporting
215+
% of spans
216+
commonSetup(testCase)
217+
218+
tp = opentelemetry.sdk.trace.TracerProvider();
219+
tr = getTracer(tp, "foo");
220+
221+
% start and end a span
222+
spanname = "bar";
223+
sp = startSpan(tr, spanname);
224+
endSpan(sp);
225+
226+
% shutdown the tracer provider
227+
verifyTrue(testCase, shutdown(tp));
228+
229+
% start and end another span
230+
sp1 = startSpan(tr, "quux");
231+
endSpan(sp1);
232+
233+
% verify only the first span was generated
234+
results = readJsonResults(testCase);
235+
verifyNumElements(testCase, results, 1);
236+
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
237+
end
238+
239+
function testCleanupSdk(testCase)
240+
% testCleanupSdk: shutdown an SDK tracer provider through the Cleanup class
241+
commonSetup(testCase)
242+
243+
tp = opentelemetry.sdk.trace.TracerProvider();
244+
tr = getTracer(tp, "foo");
245+
246+
% start and end a span
247+
spanname = "bar";
248+
sp = startSpan(tr, spanname);
249+
endSpan(sp);
250+
251+
% shutdown the SDK tracer provider through the Cleanup class
252+
verifyTrue(testCase, opentelemetry.sdk.common.Cleanup.shutdown(tp));
253+
254+
% start and end another span
255+
sp1 = startSpan(tr, "quux");
256+
endSpan(sp1);
257+
258+
% verify only the first span was generated
259+
results = readJsonResults(testCase);
260+
verifyNumElements(testCase, results, 1);
261+
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
262+
end
263+
264+
function testCleanupApi(testCase)
265+
% testCleanupApi: shutdown an API tracer provider through the Cleanup class
266+
commonSetup(testCase)
267+
268+
tp = opentelemetry.sdk.trace.TracerProvider();
269+
setTracerProvider(tp);
270+
clear("tp");
271+
tp_api = opentelemetry.trace.Provider.getTracerProvider();
272+
tr = getTracer(tp_api, "foo");
273+
274+
% start and end a span
275+
spanname = "bar";
276+
sp = startSpan(tr, spanname);
277+
endSpan(sp);
278+
279+
% shutdown the API tracer provider through the Cleanup class
280+
verifyTrue(testCase, opentelemetry.sdk.common.Cleanup.shutdown(tp_api));
281+
282+
% start and end another span
283+
sp1 = startSpan(tr, "quux");
284+
endSpan(sp1);
285+
286+
% verify only the first span was generated
287+
results = readJsonResults(testCase);
288+
verifyNumElements(testCase, results, 1);
289+
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
290+
end
212291
end
213292
end

0 commit comments

Comments
 (0)