Skip to content

Commit

Permalink
Added a unit test for the new case in sanitizeOverflowingChildren fun…
Browse files Browse the repository at this point in the history
…ction

Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
  • Loading branch information
GLVSKiriti committed Sep 12, 2023
1 parent d11d8e3 commit 67cd698
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
);
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 67cd698

Please sign in to comment.