diff --git a/packages/jaeger-ui/src/components/TracePage/CriticalPath/index.test.js b/packages/jaeger-ui/src/components/TracePage/CriticalPath/index.test.js index de447baf64..2c318d4d61 100644 --- a/packages/jaeger-ui/src/components/TracePage/CriticalPath/index.test.js +++ b/packages/jaeger-ui/src/components/TracePage/CriticalPath/index.test.js @@ -22,22 +22,26 @@ import sanitizeOverFlowingChildren from './utils/sanitizeOverFlowingChildren'; import test6 from './testCases/test6'; import test7 from './testCases/test7'; import test5 from './testCases/test5'; +import test8 from './testCases/test8'; -describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7]])('Happy Path', testProps => { - it('Should find criticalPathSections correctly', () => { - const rootSpanId = testProps.trace.spans[0].spanID; - const spanMap = testProps.trace.spans.reduce((map, span) => { - map.set(span.spanID, span); - return map; - }, new Map()); - const refinedSpanMap = getChildOfSpans(spanMap); - const sanitizedSpanMap = sanitizeOverFlowingChildren(refinedSpanMap); - const criticalPath = computeCriticalPath(sanitizedSpanMap, rootSpanId, []); - expect(criticalPath).toStrictEqual(testProps.criticalPathSections); - }); +describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7], [test8]])( + 'Happy Path', + testProps => { + it('Should find criticalPathSections correctly', () => { + const rootSpanId = testProps.trace.spans[0].spanID; + const spanMap = testProps.trace.spans.reduce((map, span) => { + map.set(span.spanID, span); + return map; + }, new Map()); + const refinedSpanMap = getChildOfSpans(spanMap); + const sanitizedSpanMap = sanitizeOverFlowingChildren(refinedSpanMap); + const criticalPath = computeCriticalPath(sanitizedSpanMap, rootSpanId, []); + expect(criticalPath).toStrictEqual(testProps.criticalPathSections); + }); - it('Critical path sections', () => { - const criticalPath = TraceCriticalPath(testProps.trace); - expect(criticalPath).toStrictEqual(testProps.criticalPathSections); - }); -}); + it('Critical path sections', () => { + const criticalPath = TraceCriticalPath(testProps.trace); + expect(criticalPath).toStrictEqual(testProps.criticalPathSections); + }); + } +); diff --git a/packages/jaeger-ui/src/components/TracePage/CriticalPath/testCases/test8.js b/packages/jaeger-ui/src/components/TracePage/CriticalPath/testCases/test8.js new file mode 100644 index 0000000000..14a85bf29c --- /dev/null +++ b/packages/jaeger-ui/src/components/TracePage/CriticalPath/testCases/test8.js @@ -0,0 +1,74 @@ +// Copyright (c) 2023 The Jaeger Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import transformTraceData from '../../../../model/transform-trace-data'; + +/* + ┌─────────────────┐ | + │ Span A │ | spanA + └─────────────────┘ | / + | / + ┌──────────────────────┐ | spanB (CHILD_OF) + │ Span B │ | + └──────────────────────┘ | ((parent-child tree)) +*/ + +const trace = { + traceID: 'trace-abc', + spans: [ + { + spanID: 'span-A', + operationName: 'op-A', + references: [], + startTime: 10, + duration: 20, + processID: 'p1', + }, + { + spanID: 'span-B', + operationName: 'op-B', + references: [ + { + refType: 'CHILD_OF', + spanID: 'span-A', + }, + ], + startTime: 5, + duration: 30, + processID: 'p1', + }, + ], + processes: { + p1: { + serviceName: 'service-one', + }, + }, +}; + +const transformedTrace = transformTraceData(trace); + +const criticalPathSections = [ + { + spanId: 'span-B', + section_start: 10, + section_end: 30, + }, +]; + +const test8 = { + criticalPathSections, + trace: transformedTrace, +}; + +export default test8; diff --git a/packages/jaeger-ui/src/components/TracePage/CriticalPath/utils/sanitizeOverFlowingChildren.test.js b/packages/jaeger-ui/src/components/TracePage/CriticalPath/utils/sanitizeOverFlowingChildren.test.js index 58a8e00666..5f49289f8b 100644 --- a/packages/jaeger-ui/src/components/TracePage/CriticalPath/utils/sanitizeOverFlowingChildren.test.js +++ b/packages/jaeger-ui/src/components/TracePage/CriticalPath/utils/sanitizeOverFlowingChildren.test.js @@ -16,6 +16,7 @@ import test3 from '../testCases/test3'; import test4 from '../testCases/test4'; import test6 from '../testCases/test6'; import test7 from '../testCases/test7'; +import test8 from '../testCases/test8'; import getChildOfSpans from './getChildOfSpans'; import sanitizeOverFlowingChildren from './sanitizeOverFlowingChildren'; @@ -24,6 +25,7 @@ function getExpectedSanitizedData(spans, test) { const testSanitizedData = { test6: [spans[0], { ...spans[1], duration: 15 }, { ...spans[2], duration: 10, startTime: 15 }], test7: [spans[0], { ...spans[1], duration: 15 }, { ...spans[2], duration: 10 }], + test8: [spans[0], { ...spans[1], startTime: 10, duration: 20 }], }; const spanMap = testSanitizedData[test].reduce((map, span) => { map.set(span.spanID, span); @@ -37,6 +39,7 @@ describe.each([ [test4, new Map().set(test4.trace.spans[0].spanID, test4.trace.spans[0])], [test6, getExpectedSanitizedData(test6.trace.spans, 'test6')], [test7, getExpectedSanitizedData(test7.trace.spans, 'test7')], + [test8, getExpectedSanitizedData(test8.trace.spans, 'test8')], ])('sanitizeOverFlowingChildren', (testProps, expectedSanitizedData) => { it('Should sanitize the data(overflowing spans) correctly', () => { const refinedSpanData = getChildOfSpans(testProps.trace.spans);