Skip to content

Commit

Permalink
Merge pull request #8771 from hashicorp/f-ui/mirage-consistency
Browse files Browse the repository at this point in the history
UI: Clean up erroneous and redundant mirage things
  • Loading branch information
DingoEatingFuzz authored Aug 28, 2020
2 parents 99a57ea + c7da3d3 commit 147a61c
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 53 deletions.
4 changes: 2 additions & 2 deletions ui/mirage/factories/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default Factory.extend({
name: () => `nomad@${faker.internet.ip()}`,

status: () => faker.helpers.randomize(AGENT_STATUSES),
serf_port: () => faker.random.number({ min: 4000, max: 4999 }),
serfPort: () => faker.random.number({ min: 4000, max: 4999 }),

address() {
return this.name.split('@')[1];
Expand All @@ -20,7 +20,7 @@ export default Factory.extend({
tags() {
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
return {
port: rpcPortCandidate === this.serf_port ? rpcPortCandidate + 1 : rpcPortCandidate,
port: rpcPortCandidate === this.serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
dc: faker.helpers.randomize(DATACENTERS),
};
},
Expand Down
1 change: 0 additions & 1 deletion ui/mirage/factories/evaluation.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function assignJob(evaluation, server) {
const job = evaluation.jobId ? server.db.jobs.find(evaluation.jobId) : pickOne(server.db.jobs);
evaluation.update({
jobId: job.id,
job_id: job.id,
});
}

Expand Down
1 change: 0 additions & 1 deletion ui/mirage/factories/job-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default Factory.extend({
// Hidden property used to compute the Summary hash
groupNames: [],

JobID: '',
namespace: null,

withSummary: trait({
Expand Down
8 changes: 2 additions & 6 deletions ui/mirage/factories/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default Factory.extend({
region: () => 'global',
type: () => faker.helpers.randomize(JOB_TYPES),
priority: () => faker.random.number(100),
all_at_once: faker.random.boolean,
allAtOnce: faker.random.boolean,
status: () => faker.helpers.randomize(JOB_STATUSES),
datacenters: () =>
faker.helpers.shuffle(DATACENTERS).slice(0, faker.random.number({ min: 1, max: 4 })),
Expand Down Expand Up @@ -141,21 +141,17 @@ export default Factory.extend({

job.update({
taskGroupIds: groups.mapBy('id'),
task_group_ids: groups.mapBy('id'),
});

const hasChildren = job.periodic || (job.parameterized && !job.parentId);
const jobSummary = server.create('job-summary', hasChildren ? 'withChildren' : 'withSummary', {
jobId: job.id,
groupNames: groups.mapBy('name'),
job,
job_id: job.id,
JobID: job.id,
namespace: job.namespace,
});

job.update({
jobSummaryId: jobSummary.id,
job_summary_id: jobSummary.id,
});

const jobScale = server.create('job-scale', {
Expand Down
2 changes: 1 addition & 1 deletion ui/mirage/factories/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default Factory.extend({
nodeClass: () => faker.helpers.randomize(NODE_CLASSES),
drain: faker.random.boolean,
status: () => faker.helpers.randomize(NODE_STATUSES),
tls_enabled: faker.random.boolean,
tlsEnabled: faker.random.boolean,
schedulingEligibility: () => (faker.random.boolean() ? 'eligible' : 'ineligible'),

createIndex: i => i,
Expand Down
3 changes: 1 addition & 2 deletions ui/mirage/factories/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export default Factory.extend({

group.update({
taskIds: taskIds,
task_ids: taskIds,
});

if (group.createAllocations) {
Expand Down Expand Up @@ -116,7 +115,7 @@ export default Factory.extend({
.fill(null)
.forEach(() => {
server.create('service', {
task_group: group,
taskGroup: group,
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions ui/mirage/models/allocation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Model, hasMany } from 'ember-cli-mirage';

export default Model.extend({
task_states: hasMany('task-state'),
task_resources: hasMany('task-resource'),
taskStates: hasMany('task-state'),
taskResources: hasMany('task-resource'),
});
5 changes: 0 additions & 5 deletions ui/mirage/models/job-summary.js

This file was deleted.

4 changes: 2 additions & 2 deletions ui/mirage/models/job.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Model, hasMany, belongsTo } from 'ember-cli-mirage';

export default Model.extend({
task_groups: hasMany('task-group'),
job_summary: belongsTo('job-summary'),
taskGroups: hasMany('task-group'),
jobSummary: belongsTo('job-summary'),
jobScale: belongsTo('job-scale'),
});
2 changes: 1 addition & 1 deletion ui/mirage/models/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Model, belongsTo } from 'ember-cli-mirage';

export default Model.extend({
task_group: belongsTo('task-group'),
taskGroup: belongsTo('task-group'),
});
2 changes: 1 addition & 1 deletion ui/mirage/serializers/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { arrToObj } from '../utils';

export default ApplicationSerializer.extend({
embed: true,
include: ['task_states', 'task_resources'],
include: ['taskStates', 'taskResources'],

serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default RestSerializer.extend({
}
},

keyForModel: keyCase,
keyForForeignKey: str => `${keyCase(str)}ID`,
keyForCollection: keyCase,
keyForAttribute: keyCase,
keyForRelationship: keyCase,
Expand Down
2 changes: 1 addition & 1 deletion ui/mirage/serializers/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
embed: true,
include: ['task_groups', 'job_summary'],
include: ['taskGroups', 'jobSummary'],

serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
Expand Down
6 changes: 4 additions & 2 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ module('Acceptance | allocation detail', function(hooks) {
jobId: job.id,
});

const taskState = allocation.task_states.models.sortBy('name')[0];
const taskState = allocation.taskStates.models.sortBy('name')[0];
const task = server.schema.tasks.findBy({ name: taskState.name });
task.update('kind', 'connect-proxy:task');
task.save();
Expand Down Expand Up @@ -295,7 +295,9 @@ module('Acceptance | allocation detail', function(hooks) {

assert.equal(renderedPort.name, serverPort.Label);
assert.equal(renderedPort.to, serverPort.To);
const expectedAddr = isIp.v6(serverPort.HostIP) ? `[${serverPort.HostIP}]:${serverPort.Value}` : `${serverPort.HostIP}:${serverPort.Value}`;
const expectedAddr = isIp.v6(serverPort.HostIP)
? `[${serverPort.HostIP}]:${serverPort.Value}`
: `${serverPort.HostIP}:${serverPort.Value}`;
assert.equal(renderedPort.address, expectedAddr);
});
});
Expand Down
38 changes: 19 additions & 19 deletions ui/tests/acceptance/exec-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module('Acceptance | exec', function(hooks) {
status: 'running',
});

this.job.task_group_ids.forEach(taskGroupId => {
this.job.taskGroups.models.forEach(taskGroup => {
server.create('allocation', {
jobId: this.job.id,
taskGroup: server.db.taskGroups.find(taskGroupId).name,
taskGroup: taskGroup.name,
forceRunningClientStatus: true,
});
});
Expand Down Expand Up @@ -71,10 +71,10 @@ module('Acceptance | exec', function(hooks) {
});

test('/exec/:job should show the task groups collapsed by default and allow the tasks to be shown', async function(assert) {
const firstTaskGroup = this.job.task_groups.models.sortBy('name')[0];
const firstTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
await Exec.visitJob({ job: this.job.id });

assert.equal(Exec.taskGroups.length, this.job.task_groups.length);
assert.equal(Exec.taskGroups.length, this.job.taskGroups.length);

assert.equal(Exec.taskGroups[0].name, firstTaskGroup.name);
assert.equal(Exec.taskGroups[0].tasks.length, 0);
Expand Down Expand Up @@ -103,29 +103,29 @@ module('Acceptance | exec', function(hooks) {
});

test('a task group with a pending allocation shows a loading spinner', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'pending' });

await Exec.visitJob({ job: this.job.id });
assert.ok(Exec.taskGroups[0].isLoading);
});

test('a task group with no running task states or pending allocations should not be shown', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'failed' });

await Exec.visitJob({ job: this.job.id });
assert.notEqual(Exec.taskGroups[0].name, taskGroup.name);
});

test('an inactive task should not be shown', async function(assert) {
let notRunningTaskGroup = this.job.task_groups.models.sortBy('name')[0];
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update(
{ taskGroup: notRunningTaskGroup.name },
{ clientStatus: 'failed' }
);

let runningTaskGroup = this.job.task_groups.models.sortBy('name')[1];
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
runningTaskGroup.tasks.models.forEach((task, index) => {
if (index > 0) {
this.server.db.taskStates.update({ name: task.name }, { finishedAt: new Date() });
Expand All @@ -139,13 +139,13 @@ module('Acceptance | exec', function(hooks) {
});

test('a task that becomes active should appear', async function(assert) {
let notRunningTaskGroup = this.job.task_groups.models.sortBy('name')[0];
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update(
{ taskGroup: notRunningTaskGroup.name },
{ clientStatus: 'failed' }
);

let runningTaskGroup = this.job.task_groups.models.sortBy('name')[1];
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
let changingTaskStateName;
runningTaskGroup.tasks.models.sortBy('name').forEach((task, index) => {
if (index > 0) {
Expand Down Expand Up @@ -184,7 +184,7 @@ module('Acceptance | exec', function(hooks) {
this.job.status = 'dead';
this.job.save();

let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];

this.server.db.taskStates.update({ finishedAt: new Date() });
Expand Down Expand Up @@ -217,7 +217,7 @@ module('Acceptance | exec', function(hooks) {
});

test('visiting a path with a task group should open the group by default', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
await Exec.visitTaskGroup({ job: this.job.id, task_group: taskGroup.name });

assert.equal(Exec.taskGroups[0].tasks.length, taskGroup.tasks.length);
Expand All @@ -235,7 +235,7 @@ module('Acceptance | exec', function(hooks) {
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();

let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];

let taskStates = this.server.db.taskStates.where({
Expand Down Expand Up @@ -274,7 +274,7 @@ module('Acceptance | exec', function(hooks) {
});

test('an allocation can be specified', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
Expand Down Expand Up @@ -322,7 +322,7 @@ module('Acceptance | exec', function(hooks) {

this.owner.register('service:sockets', mockSockets);

let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
Expand Down Expand Up @@ -393,7 +393,7 @@ module('Acceptance | exec', function(hooks) {

this.owner.register('service:sockets', mockSockets);

let taskGroup = this.job.task_groups.models[0];
let taskGroup = this.job.taskGroups.models[0];
let task = taskGroup.tasks.models[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
Expand Down Expand Up @@ -463,7 +463,7 @@ module('Acceptance | exec', function(hooks) {
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();

let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocation = this.server.db.allocations.findBy({
jobId: this.job.id,
Expand Down Expand Up @@ -509,7 +509,7 @@ module('Acceptance | exec', function(hooks) {
test('a persisted customised command is recalled', async function(assert) {
window.localStorage.setItem('nomadExecCommand', JSON.stringify('/bin/sh'));

let taskGroup = this.job.task_groups.models[0];
let taskGroup = this.job.taskGroups.models[0];
let task = taskGroup.tasks.models[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
Expand All @@ -536,7 +536,7 @@ module('Acceptance | exec', function(hooks) {
});

skip('when a task state finishes submitting a command displays an error', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];

await Exec.visitTask({
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/servers-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module('Acceptance | servers list', function(hooks) {
assert.equal(agentRow.status, agent.status, 'Status');
assert.equal(agentRow.leader, 'True', 'Leader?');
assert.equal(agentRow.address, agent.address, 'Address');
assert.equal(agentRow.serfPort, agent.serf_port, 'Serf Port');
assert.equal(agentRow.serfPort, agent.serfPort, 'Serf Port');
assert.equal(agentRow.datacenter, agent.tags.dc, 'Datacenter');
});

Expand Down
10 changes: 5 additions & 5 deletions ui/tests/acceptance/task-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ module('Acceptance | task detail', function(hooks) {
status: 'running',
});

job.task_group_ids.forEach(taskGroupId => {
job.taskGroups.models.forEach(taskGroup => {
server.create('allocation', {
jobId: job.id,
taskGroup: server.db.taskGroups.find(taskGroupId).name,
taskGroup: taskGroup.name,
forceRunningClientStatus: true,
});
});

const taskGroup = job.task_groups.models[0];
const taskGroup = job.taskGroups.models[0];
const [mainTask, sidecarTask, prestartTask] = taskGroup.tasks.models;

mainTask.attrs.Lifecycle = null;
Expand All @@ -131,7 +131,7 @@ module('Acceptance | task detail', function(hooks) {

taskGroup.save();

const noPrestartTasksTaskGroup = job.task_groups.models[1];
const noPrestartTasksTaskGroup = job.taskGroups.models[1];
noPrestartTasksTaskGroup.tasks.models.forEach(task => {
task.attrs.Lifecycle = null;
task.save();
Expand Down Expand Up @@ -421,7 +421,7 @@ module('Acceptance | proxy task detail', function(hooks) {
server.create('job', { createAllocations: false });
allocation = server.create('allocation', 'withTaskWithPorts', { clientStatus: 'running' });

const taskState = allocation.task_states.models[0];
const taskState = allocation.taskStates.models[0];
const task = server.schema.tasks.findBy({ name: taskState.name });
task.update('kind', 'connect-proxy:task');
task.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module('Integration | Component | scale-events-accordion', function(hooks) {
this.server.create('node');
this.taskGroupWithEvents = async function(events) {
const job = this.server.create('job', { createAllocations: false });
const group = job.task_groups.models[0];
const group = job.taskGroups.models[0];
job.jobScale.taskGroupScales.models.findBy('name', group.name).update({ events });

const jobModel = await this.store.find('job', JSON.stringify([job.id, 'default']));
Expand Down

0 comments on commit 147a61c

Please sign in to comment.