github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/acceptance/task-group-detail-test.js (about)

     1  import { click, find, findAll, fillIn, currentURL, visit } from 'ember-native-dom-helpers';
     2  import { test } from 'qunit';
     3  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     4  import { formatBytes } from 'nomad-ui/helpers/format-bytes';
     5  import moment from 'moment';
     6  
     7  let job;
     8  let taskGroup;
     9  let tasks;
    10  let allocations;
    11  
    12  const sum = (total, n) => total + n;
    13  
    14  moduleForAcceptance('Acceptance | task group detail', {
    15    beforeEach() {
    16      server.create('agent');
    17      server.create('node', 'forceIPv4');
    18  
    19      job = server.create('job', {
    20        groupsCount: 2,
    21        createAllocations: false,
    22      });
    23  
    24      const taskGroups = server.db.taskGroups.where({ jobId: job.id });
    25      taskGroup = taskGroups[0];
    26  
    27      tasks = taskGroup.taskIds.map(id => server.db.tasks.find(id));
    28  
    29      server.create('node', 'forceIPv4');
    30  
    31      allocations = server.createList('allocation', 2, {
    32        jobId: job.id,
    33        taskGroup: taskGroup.name,
    34      });
    35  
    36      // Allocations associated to a different task group on the job to
    37      // assert that they aren't showing up in on this page in error.
    38      server.createList('allocation', 3, {
    39        jobId: job.id,
    40        taskGroup: taskGroups[1].name,
    41      });
    42  
    43      // Set a static name to make the search test deterministic
    44      server.db.allocations.forEach(alloc => {
    45        alloc.name = 'aaaaa';
    46      });
    47  
    48      visit(`/jobs/${job.id}/${taskGroup.name}`);
    49    },
    50  });
    51  
    52  test('/jobs/:id/:task-group should list high-level metrics for the allocation', function(assert) {
    53    const totalCPU = tasks.mapBy('Resources.CPU').reduce(sum, 0);
    54    const totalMemory = tasks.mapBy('Resources.MemoryMB').reduce(sum, 0);
    55    const totalDisk = taskGroup.ephemeralDisk.SizeMB;
    56  
    57    assert.equal(
    58      find('[data-test-task-group-tasks]').textContent,
    59      `# Tasks ${tasks.length}`,
    60      '# Tasks'
    61    );
    62    assert.equal(
    63      find('[data-test-task-group-cpu]').textContent,
    64      `Reserved CPU ${totalCPU} MHz`,
    65      'Aggregated CPU reservation for all tasks'
    66    );
    67    assert.equal(
    68      find('[data-test-task-group-mem]').textContent,
    69      `Reserved Memory ${totalMemory} MiB`,
    70      'Aggregated Memory reservation for all tasks'
    71    );
    72    assert.equal(
    73      find('[data-test-task-group-disk]').textContent,
    74      `Reserved Disk ${totalDisk} MiB`,
    75      'Aggregated Disk reservation for all tasks'
    76    );
    77  });
    78  
    79  test('/jobs/:id/:task-group should have breadcrumbs for job and jobs', function(assert) {
    80    assert.equal(
    81      find('[data-test-breadcrumb="Jobs"]').textContent.trim(),
    82      'Jobs',
    83      'First breadcrumb says jobs'
    84    );
    85    assert.equal(
    86      find(`[data-test-breadcrumb="${job.name}"]`).textContent.trim(),
    87      job.name,
    88      'Second breadcrumb says the job name'
    89    );
    90    assert.equal(
    91      find(`[data-test-breadcrumb="${taskGroup.name}"]`).textContent.trim(),
    92      taskGroup.name,
    93      'Third breadcrumb says the job name'
    94    );
    95  });
    96  
    97  test('/jobs/:id/:task-group first breadcrumb should link to jobs', function(assert) {
    98    click('[data-test-breadcrumb="Jobs"]');
    99    andThen(() => {
   100      assert.equal(currentURL(), '/jobs', 'First breadcrumb links back to jobs');
   101    });
   102  });
   103  
   104  test('/jobs/:id/:task-group second breadcrumb should link to the job for the task group', function(assert) {
   105    click(`[data-test-breadcrumb="${job.name}"]`);
   106    andThen(() => {
   107      assert.equal(
   108        currentURL(),
   109        `/jobs/${job.id}`,
   110        'Second breadcrumb links back to the job for the task group'
   111      );
   112    });
   113  });
   114  
   115  test('/jobs/:id/:task-group should list one page of allocations for the task group', function(assert) {
   116    const pageSize = 10;
   117  
   118    server.createList('allocation', 10, {
   119      jobId: job.id,
   120      taskGroup: taskGroup.name,
   121    });
   122  
   123    visit('/jobs');
   124    visit(`/jobs/${job.id}/${taskGroup.name}`);
   125  
   126    andThen(() => {
   127      assert.ok(
   128        server.db.allocations.where({ jobId: job.id }).length > pageSize,
   129        'There are enough allocations to invoke pagination'
   130      );
   131  
   132      assert.equal(
   133        findAll('[data-test-allocation]').length,
   134        pageSize,
   135        'All allocations for the task group'
   136      );
   137    });
   138  });
   139  
   140  test('each allocation should show basic information about the allocation', function(assert) {
   141    const allocation = allocations.sortBy('modifyIndex').reverse()[0];
   142    const allocationRow = find('[data-test-allocation]');
   143  
   144    andThen(() => {
   145      assert.equal(
   146        allocationRow.querySelector('[data-test-short-id]').textContent.trim(),
   147        allocation.id.split('-')[0],
   148        'Allocation short id'
   149      );
   150      assert.equal(
   151        allocationRow.querySelector('[data-test-modify-time]').textContent.trim(),
   152        moment(allocation.modifyTime / 1000000).format('MM/DD HH:mm:ss'),
   153        'Allocation modify time'
   154      );
   155      assert.equal(
   156        allocationRow.querySelector('[data-test-name]').textContent.trim(),
   157        allocation.name,
   158        'Allocation name'
   159      );
   160      assert.equal(
   161        allocationRow.querySelector('[data-test-client-status]').textContent.trim(),
   162        allocation.clientStatus,
   163        'Client status'
   164      );
   165      assert.equal(
   166        allocationRow.querySelector('[data-test-job-version]').textContent.trim(),
   167        allocation.jobVersion,
   168        'Job Version'
   169      );
   170      assert.equal(
   171        allocationRow.querySelector('[data-test-client]').textContent.trim(),
   172        server.db.nodes.find(allocation.nodeId).id.split('-')[0],
   173        'Node ID'
   174      );
   175    });
   176  
   177    click(allocationRow.querySelector('[data-test-client] a'));
   178  
   179    andThen(() => {
   180      assert.equal(currentURL(), `/clients/${allocation.nodeId}`, 'Node links to node page');
   181    });
   182  });
   183  
   184  test('each allocation should show stats about the allocation', function(assert) {
   185    const allocation = allocations.sortBy('name')[0];
   186    const allocationRow = find('[data-test-allocation]');
   187    const allocStats = server.db.clientAllocationStats.find(allocation.id);
   188    const tasks = taskGroup.taskIds.map(id => server.db.tasks.find(id));
   189  
   190    const cpuUsed = tasks.reduce((sum, task) => sum + task.Resources.CPU, 0);
   191    const memoryUsed = tasks.reduce((sum, task) => sum + task.Resources.MemoryMB, 0);
   192  
   193    assert.equal(
   194      allocationRow.querySelector('[data-test-cpu]').textContent.trim(),
   195      Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
   196      'CPU %'
   197    );
   198  
   199    assert.equal(
   200      allocationRow.querySelector('[data-test-cpu] .tooltip').getAttribute('aria-label'),
   201      `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`,
   202      'Detailed CPU information is in a tooltip'
   203    );
   204  
   205    assert.equal(
   206      allocationRow.querySelector('[data-test-mem]').textContent.trim(),
   207      allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
   208      'Memory used'
   209    );
   210  
   211    assert.equal(
   212      allocationRow.querySelector('[data-test-mem] .tooltip').getAttribute('aria-label'),
   213      `${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
   214      'Detailed memory information is in a tooltip'
   215    );
   216  });
   217  
   218  test('when the allocation search has no matches, there is an empty message', function(assert) {
   219    fillIn('.search-box input', 'zzzzzz');
   220  
   221    andThen(() => {
   222      assert.ok(find('[data-test-empty-allocations-list]'));
   223      assert.equal(find('[data-test-empty-allocations-list-headline]').textContent, 'No Matches');
   224    });
   225  });