Skip to content

Commit

Permalink
Merge pull request #59 from mathworks/metrics_merge
Browse files Browse the repository at this point in the history
Add shutdown tests to ttrace_sdk
  • Loading branch information
duncanpo authored Nov 14, 2023
2 parents 10b014c + 9222d37 commit 9185f37
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions test/ttrace_sdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,84 @@ function testCustomResource(testCase)
verifyEqual(testCase, results.resourceSpans.resource.attributes(idx).value.doubleValue, customvalues(i));
end
end

function testShutdown(testCase)
% testShutdown: shutdown method should stop exporting
% of spans
commonSetup(testCase)

tp = opentelemetry.sdk.trace.TracerProvider();
tr = getTracer(tp, "foo");

% start and end a span
spanname = "bar";
sp = startSpan(tr, spanname);
endSpan(sp);

% shutdown the tracer provider
verifyTrue(testCase, shutdown(tp));

% start and end another span
sp1 = startSpan(tr, "quux");
endSpan(sp1);

% verify only the first span was generated
results = readJsonResults(testCase);
verifyNumElements(testCase, results, 1);
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
end

function testCleanupSdk(testCase)
% testCleanupSdk: shutdown an SDK tracer provider through the Cleanup class
commonSetup(testCase)

tp = opentelemetry.sdk.trace.TracerProvider();
tr = getTracer(tp, "foo");

% start and end a span
spanname = "bar";
sp = startSpan(tr, spanname);
endSpan(sp);

% shutdown the SDK tracer provider through the Cleanup class
verifyTrue(testCase, opentelemetry.sdk.common.Cleanup.shutdown(tp));

% start and end another span
sp1 = startSpan(tr, "quux");
endSpan(sp1);

% verify only the first span was generated
results = readJsonResults(testCase);
verifyNumElements(testCase, results, 1);
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
end

function testCleanupApi(testCase)
% testCleanupApi: shutdown an API tracer provider through the Cleanup class
commonSetup(testCase)

tp = opentelemetry.sdk.trace.TracerProvider();
setTracerProvider(tp);
clear("tp");
tp_api = opentelemetry.trace.Provider.getTracerProvider();
tr = getTracer(tp_api, "foo");

% start and end a span
spanname = "bar";
sp = startSpan(tr, spanname);
endSpan(sp);

% shutdown the API tracer provider through the Cleanup class
verifyTrue(testCase, opentelemetry.sdk.common.Cleanup.shutdown(tp_api));

% start and end another span
sp1 = startSpan(tr, "quux");
endSpan(sp1);

% verify only the first span was generated
results = readJsonResults(testCase);
verifyNumElements(testCase, results, 1);
verifyEqual(testCase, string(results{1}.resourceSpans.scopeSpans.spans.name), spanname);
end
end
end

0 comments on commit 9185f37

Please sign in to comment.