mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
Address missing job events.
- Fix off by one error. - Add unit tests for Stream Service.
This commit is contained in:
@@ -50,6 +50,10 @@ function OutputStream ($q) {
|
|||||||
this.calcFactors = size => {
|
this.calcFactors = size => {
|
||||||
const factors = [1];
|
const factors = [1];
|
||||||
|
|
||||||
|
if (size !== parseInt(size, 10) || size <= 1) {
|
||||||
|
return factors;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 2; i <= size / 2; i++) {
|
for (let i = 2; i <= size / 2; i++) {
|
||||||
if (size % i === 0) {
|
if (size % i === 0) {
|
||||||
factors.push(i);
|
factors.push(i);
|
||||||
@@ -135,7 +139,7 @@ function OutputStream ($q) {
|
|||||||
|
|
||||||
this.isReadyToRender = () => {
|
this.isReadyToRender = () => {
|
||||||
const { total } = this.counters;
|
const { total } = this.counters;
|
||||||
const readyCount = this.counters.ready - this.counters.min;
|
const readyCount = this.getReadyCount();
|
||||||
|
|
||||||
if (readyCount <= 0) {
|
if (readyCount <= 0) {
|
||||||
return false;
|
return false;
|
||||||
@@ -202,7 +206,7 @@ function OutputStream ($q) {
|
|||||||
return $q.resolve();
|
return $q.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
const readyCount = this.counters.ready - this.counters.min;
|
const readyCount = this.getReadyCount();
|
||||||
|
|
||||||
let events = [];
|
let events = [];
|
||||||
if (readyCount > 0) {
|
if (readyCount > 0) {
|
||||||
@@ -230,6 +234,7 @@ function OutputStream ($q) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.getMaxCounter = () => this.counters.max;
|
this.getMaxCounter = () => this.counters.max;
|
||||||
|
this.getReadyCount = () => this.counters.ready - this.counters.min + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStream.$inject = ['$q'];
|
OutputStream.$inject = ['$q'];
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ import './side-nav.unit';
|
|||||||
import './side-nav-item.unit';
|
import './side-nav-item.unit';
|
||||||
import './jobs-list-split-jobs.unit';
|
import './jobs-list-split-jobs.unit';
|
||||||
import './job-details-split-jobs.unit';
|
import './job-details-split-jobs.unit';
|
||||||
|
import './stream.unit';
|
||||||
|
|||||||
96
awx/ui/test/unit/components/stream.unit.js
Normal file
96
awx/ui/test/unit/components/stream.unit.js
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import StreamService from '~features/output/stream.service';
|
||||||
|
|
||||||
|
describe('Output | StreamService', () => {
|
||||||
|
angular.module('test', []).service('StreamService', StreamService);
|
||||||
|
let stream;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
angular.mock.module('test');
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(angular.mock.inject(($injector) => {
|
||||||
|
stream = $injector.get('StreamService');
|
||||||
|
|
||||||
|
const onFrames = angular.noop;
|
||||||
|
const onFrameRate = angular.noop;
|
||||||
|
|
||||||
|
stream.init({ onFrames, onFrameRate });
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('calcFactors', () => {
|
||||||
|
it('returns the expected values', () => {
|
||||||
|
const params = [
|
||||||
|
[-1, [1]],
|
||||||
|
[0, [1]],
|
||||||
|
[1, [1]],
|
||||||
|
[1.0, [1]],
|
||||||
|
[1.1, [1]],
|
||||||
|
[2, [1, 2]],
|
||||||
|
['1', [1]],
|
||||||
|
[{}, [1]],
|
||||||
|
[null, [1]],
|
||||||
|
[undefined, [1]],
|
||||||
|
[250, [1, 2, 5, 10, 25, 50, 125, 250]]
|
||||||
|
];
|
||||||
|
|
||||||
|
params.forEach(([size, expected]) => expect(stream.calcFactors(size)).toEqual(expected));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setMissingCounterThreshold', () => {
|
||||||
|
it('returns the correct counter threshold', () => {
|
||||||
|
const gt = 2;
|
||||||
|
stream.setMissingCounterThreshold(gt);
|
||||||
|
expect(stream.counters.min).toEqual(gt);
|
||||||
|
|
||||||
|
const lt = -1;
|
||||||
|
stream.setMissingCounterThreshold(lt);
|
||||||
|
expect(stream.counters.min).toEqual(gt);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isReadyToRender', () => {
|
||||||
|
it('returns false', () => {
|
||||||
|
const res = stream.isReadyToRender();
|
||||||
|
expect(res).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true', () => {
|
||||||
|
stream.state.ending = true;
|
||||||
|
let res = stream.isReadyToRender();
|
||||||
|
expect(res).toBe(true);
|
||||||
|
|
||||||
|
stream.counters.total = 1;
|
||||||
|
stream.framesPerRender = 1;
|
||||||
|
|
||||||
|
res = stream.isReadyToRender();
|
||||||
|
expect(res).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getMaxCounter', () => {
|
||||||
|
it('returns the same value as max counter', () => {
|
||||||
|
const res = stream.getMaxCounter();
|
||||||
|
expect(res).toEqual(stream.counters.max);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getReadyCount', () => {
|
||||||
|
it('references min and max counters', () => {
|
||||||
|
expect(stream.getReadyCount()).toEqual(stream.counters.max - stream.counters.min + 1);
|
||||||
|
});
|
||||||
|
it('returns expected values if min or max value is a non-integer', () => {
|
||||||
|
const params = [
|
||||||
|
[null, 1, 0],
|
||||||
|
[undefined, 1, NaN],
|
||||||
|
['1', 1, 1]
|
||||||
|
];
|
||||||
|
|
||||||
|
params.forEach(([x, y, z]) => {
|
||||||
|
stream.counters.ready = x;
|
||||||
|
stream.counters.min = y;
|
||||||
|
expect(stream.getReadyCount()).toEqual(z);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user