Skip to content

Commit

Permalink
Testfixes for new meta structure on tasks and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Dec 5, 2024
1 parent 2f5069a commit 54c2ad0
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ui/app/models/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class TaskGroup extends Fragment {
get mergedMeta() {
return {
...this.job.get('meta.raw'),
...this.meta,
...this.get('meta.raw'),
};
}

Expand Down
2 changes: 1 addition & 1 deletion ui/app/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class Task extends Fragment {
get mergedMeta() {
return {
...this.taskGroup.mergedMeta,
...this.meta,
...this.get('meta.raw'),

Check failure on line 32 in ui/app/models/task.js

View workflow job for this annotation

GitHub Actions / pre-test

The this.get() method is a classic ember object method, and can't be used in octane classes. You can refactor this usage to use a utility version instead (e.g. get(this, 'foo')), or to use native/modern syntax instead. Alternatively, you can add the @classic decorator to this class to continue using classic APIs
};
}

Expand Down
4 changes: 4 additions & 0 deletions ui/mirage/factories/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default Factory.extend({
// When true, the group will simulate a "scheduled" block's paused state
withPausedTasks: false,

// When true, the tasks will have metadata
withTaskMeta: false,

afterCreate(group, server) {
let taskIds = [];
let volumes = Object.keys(group.volumes);
Expand Down Expand Up @@ -114,6 +117,7 @@ export default Factory.extend({
})),
createRecommendations: group.createRecommendations,
withSchedule: group.withPausedTasks,
withMeta: group.withTaskMeta,
});
});
taskIds = tasks.mapBy('id');
Expand Down
6 changes: 6 additions & 0 deletions ui/mirage/factories/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default Factory.extend({
// Set in the TaskGroup factory
volumeMounts: [],

meta: null,

JobID: '',

name: (id) => `task-${dasherize(faker.hacker.noun())}-${id}`,
Expand Down Expand Up @@ -128,5 +130,9 @@ export default Factory.extend({
});
task.update({ schedule: schedule });
}

if (task.withMeta) {
task.update({ meta: { raw: { foo: 'bar' } } });
}
},
});
24 changes: 23 additions & 1 deletion ui/tests/acceptance/task-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import Task from 'nomad-ui/tests/pages/allocations/task/detail';
import Layout from 'nomad-ui/tests/pages/layout';
import moment from 'moment';

import { set } from '@ember/object';

Check failure on line 15 in ui/tests/acceptance/task-detail-test.js

View workflow job for this annotation

GitHub Actions / pre-test

'set' is defined but never used
let allocation;
let task;

Expand Down Expand Up @@ -213,6 +213,28 @@ module('Acceptance | task detail', function (hooks) {
});
});

test('when a task group has metadata, the metadata table is shown', async function (assert) {
const job = server.create('job', {
createAllocations: false,
});
const taskGroup = server.create('task-group', {
job,
name: 'scaling',
count: 1,
withTaskMeta: true,
});
job.update({ taskGroupIds: [taskGroup.id] });
allocation = server.db.allocations[1];
server.db.taskStates.update(
{ allocationId: allocation.id },
{ state: 'running' }
);
const jobTask = taskGroup.tasks.models[0];
task = jobTask;
await Task.visit({ id: allocation.id, name: task.name });
assert.ok(Task.hasMeta);
});

test('each recent event should list the time, type, and description of the event', async function (assert) {
const event = server.db.taskEvents.where({ taskStateId: task.id })[0];
const recentEvent = Task.events.objectAt(Task.events.length - 1);
Expand Down
7 changes: 7 additions & 0 deletions ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ module('Acceptance | task group detail', function (hooks) {
});

test('when the task group has metadata, the metadata table is shown', async function (assert) {
job = server.create('job', {
meta: { raw: { a: 'b' } },
});
taskGroup = server.create('task-group', {
job,
meta: { raw: { foo: 'bar' } },
});
await TaskGroup.visit({ id: job.id, name: taskGroup.name });

assert.ok(TaskGroup.hasMeta);
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/pages/allocations/task/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default create({
clientSource: text('[data-test-volume-client-source]'),
}),

hasMeta: isPresent('[data-test-meta]'),

events: collection('[data-test-task-event]', {
time: text('[data-test-task-event-time]'),
type: text('[data-test-task-event-type]'),
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/pages/jobs/job/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export default create({
permissions: text('[data-test-volume-permissions]'),
}),

hasMeta: isPresent('[data-test-meta]'),

hasScaleEvents: isPresent('[data-test-scale-events]'),
scaleEvents: collection(
'[data-test-scale-events] [data-test-accordion-head]',
Expand Down
16 changes: 7 additions & 9 deletions ui/tests/unit/models/task-group-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,22 @@ module('Unit | Model | task-group', function (hooks) {
const jobWithMeta = run(() =>
store.createRecord('job', {
name: 'example-with-meta',
meta: store.createFragment('structured-attributes', {
raw: { a: 'b' },
}),
meta: { raw: { a: 'b' } },
taskGroups: [
{
name: 'one',
meta: { c: 'd' },
meta: { raw: { c: 'd' } },
},
{
name: 'two',
},
{
name: 'three',
meta: null,
meta: { raw: null },
},
{
name: 'four',
meta: {},
meta: { raw: {} },
},
],
})
Expand All @@ -114,18 +112,18 @@ module('Unit | Model | task-group', function (hooks) {
taskGroups: [
{
name: 'one',
meta: { c: 'd' },
meta: { raw: { c: 'd' } },
},
{
name: 'two',
},
{
name: 'three',
meta: null,
meta: { raw: null },
},
{
name: 'four',
meta: {},
meta: { raw: {} },
},
],
})
Expand Down
14 changes: 7 additions & 7 deletions ui/tests/unit/models/task-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ module('Unit | Model | task', function (hooks) {
taskGroups: [
{
name: 'one',
meta: { a: 'b' },
meta: { raw: { a: 'b' } },
tasks: [
{
name: 'task-one',
meta: { c: 'd' },
meta: { raw: { c: 'd' } },
},
{
name: 'task-two',
},
{
name: 'task-three',
meta: null,
meta: { raw: null },
},
{
name: 'task-four',
meta: {},
meta: { raw: {} },
},
],
},
Expand All @@ -44,18 +44,18 @@ module('Unit | Model | task', function (hooks) {
tasks: [
{
name: 'task-one',
meta: { c: 'd' },
meta: { raw: { c: 'd' } },
},
{
name: 'task-two',
},
{
name: 'task-three',
meta: null,
meta: { raw: null },
},
{
name: 'task-four',
meta: {},
meta: { raw: {} },
},
],
},
Expand Down

0 comments on commit 54c2ad0

Please sign in to comment.