COVESA / COVESA/iot-event-analytics

Misleading log statement on feature cycle

Open
#121 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
26
Forks
14
PR merge metrics
No merged PRs in 30d

Description

There's a log statement for feature cycles which prints a wrong cycle.

This can be reproduced using this unit test for the FeatureCycle class:

```javascript
it('should log the correct dependency cycle', () => {
spyOn(fg.logger, 'warn').and.callThrough();
fg.addDependency('1', '2');
fg.addDependency('3', '3');;
expect(fg.containsCycles()).toBeTruthy();
// will currently log "1 -> 2"
expect(fg.logger.warn).toHaveBeenCalledWith('Feature cycle found in path "3 -> 3"');
});
```

The wrong log message is produced by the `if`-statement in [featureGraph.js:142](https://github.com/GENIVI/iot-event-analytics/blob/07767e2fe3824fb7f26d306f8c40146ca80492d5/src/core/util/featureGraph.js#L142).

A possible fix could be to move the `if`-statement out of the surrounding `for`-loop (as it does not use the `path` parameter of the loop) and rewrite it to remember the found cycles:
```javascript
const pathsWithCycles = paths.reduce((cycles, path) => (new Set(path)).size !== path.length ? [...cycles, path] : cycles, []);
if (pathsWithCycles.length !== 0) {
pathsWithCycles.forEach(path => this.logger.warn(`Feature cycle found in path ${serializePath(path)}`));
return true;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.