open-nomad/ui/tests/unit/models/job-test.js

131 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-02-16 02:55:59 +00:00
import { getOwner } from '@ember/application';
import { run } from '@ember/runloop';
2017-09-19 14:47:10 +00:00
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('job', 'Unit | Model | job', {
2018-02-16 02:55:59 +00:00
needs: ['model:job-summary', 'model:task-group', 'model:task', 'model:task-group-summary'],
2017-09-19 14:47:10 +00:00
});
test('should expose aggregate allocations derived from task groups', function(assert) {
2018-02-16 02:55:59 +00:00
const store = getOwner(this).lookup('service:store');
let summary;
run(() => {
summary = store.createRecord('job-summary', {
taskGroupSummaries: [
{
name: 'one',
queuedAllocs: 1,
startingAllocs: 2,
runningAllocs: 3,
completeAllocs: 4,
failedAllocs: 5,
lostAllocs: 6,
},
{
name: 'two',
queuedAllocs: 2,
startingAllocs: 4,
runningAllocs: 6,
completeAllocs: 8,
failedAllocs: 10,
lostAllocs: 12,
},
{
name: 'three',
queuedAllocs: 3,
startingAllocs: 6,
runningAllocs: 9,
completeAllocs: 12,
failedAllocs: 15,
lostAllocs: 18,
},
],
});
});
2017-09-19 14:47:10 +00:00
const job = this.subject({
2018-02-16 02:55:59 +00:00
summary,
2017-09-19 14:47:10 +00:00
name: 'example',
taskGroups: [
{
name: 'one',
count: 0,
tasks: [],
},
{
name: 'two',
count: 0,
tasks: [],
},
{
name: 'three',
count: 0,
tasks: [],
},
],
});
assert.equal(
job.get('totalAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.totalAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'totalAllocs is the sum of all group totalAllocs'
);
assert.equal(
job.get('queuedAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.queuedAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'queuedAllocs is the sum of all group queuedAllocs'
);
assert.equal(
job.get('startingAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.startingAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'startingAllocs is the sum of all group startingAllocs'
);
assert.equal(
job.get('runningAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.runningAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'runningAllocs is the sum of all group runningAllocs'
);
assert.equal(
job.get('completeAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.completeAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'completeAllocs is the sum of all group completeAllocs'
);
assert.equal(
job.get('failedAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.failedAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'failedAllocs is the sum of all group failedAllocs'
);
assert.equal(
job.get('lostAllocs'),
2018-02-16 02:55:59 +00:00
job
.get('taskGroups')
.mapBy('summary.lostAllocs')
.reduce((sum, allocs) => sum + allocs, 0),
2017-09-19 14:47:10 +00:00
'lostAllocs is the sum of all group lostAllocs'
);
});