Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolver] Remove useless check that breaks when tree has no nodes #73583

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
mockTreeWith2AncestorsAndNoChildren,
mockTreeWith1AncestorAnd2ChildrenAndAllNodesHave2GraphableEvents,
mockTreeWithAllProcessesTerminated,
mockTreeWithNoProcessEvents,
} from '../mocks/resolver_tree';
import { uniquePidForProcess } from '../../models/process_event';
import { EndpointEvent } from '../../../../common/endpoint/types';
Expand Down Expand Up @@ -408,4 +409,26 @@ describe('data state', () => {
expect(selectors.graphableProcesses(state()).length).toBe(4);
});
});
describe('with a tree with no process events', () => {
beforeEach(() => {
const tree = mockTreeWithNoProcessEvents();
actions.push({
type: 'serverReturnedResolverData',
payload: {
result: tree,
// this value doesn't matter
databaseDocumentID: '',
},
});
});
it('should return an empty layout', () => {
expect(selectors.layout(state())).toMatchInlineSnapshot(`
Object {
"ariaLevels": Map {},
"edgeLineSegments": Array [],
"processNodePositions": Map {},
}
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ export const layout = createSelector(
// find the origin node
const originNode = indexedProcessTreeModel.processEvent(indexedProcessTree, originID);

if (!originNode) {
// this should only happen if the `ResolverTree` from the server has an entity ID with no matching lifecycle events.
throw new Error('Origin node not found in ResolverTree');
if (originNode === null) {
// If a tree is returned that has no process events for the origin, this can happen.
return taxiLayout;
}

// Find the position of the origin, we'll center the map on it intrinsically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,33 @@ export function mockTreeWith1AncestorAnd2ChildrenAndAllNodesHave2GraphableEvents
lifecycle: [origin, originClone],
} as unknown) as ResolverTree;
}

export function mockTreeWithNoProcessEvents(): ResolverTree {
return {
entityID: 'entityID',
children: {
childNodes: [],
nextChild: null,
},
relatedEvents: {
events: [],
nextEvent: null,
},
relatedAlerts: {
alerts: [],
nextAlert: null,
},
lifecycle: [],
ancestry: {
ancestors: [],
nextAncestor: null,
},
stats: {
totalAlerts: 0,
events: {
total: 0,
byCategory: {},
},
},
};
}