diff --git a/test/ttrace_sdk.m b/test/ttrace_sdk.m index 2040c55..bcddf69 100644 --- a/test/ttrace_sdk.m +++ b/test/ttrace_sdk.m @@ -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 \ No newline at end of file