github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/acceptance/plugin-detail-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { currentURL } from '@ember/test-helpers';
     3  import { setupApplicationTest } from 'ember-qunit';
     4  import { setupMirage } from 'ember-cli-mirage/test-support';
     5  import moment from 'moment';
     6  import { formatBytes } from 'nomad-ui/helpers/format-bytes';
     7  import PluginDetail from 'nomad-ui/tests/pages/storage/plugins/detail';
     8  
     9  module('Acceptance | plugin detail', function(hooks) {
    10    setupApplicationTest(hooks);
    11    setupMirage(hooks);
    12  
    13    let plugin;
    14  
    15    hooks.beforeEach(function() {
    16      server.create('node');
    17      plugin = server.create('csi-plugin');
    18    });
    19  
    20    test('/csi/plugins/:id should have a breadcrumb trail linking back to Plugins and Storage', async function(assert) {
    21      await PluginDetail.visit({ id: plugin.id });
    22  
    23      assert.equal(PluginDetail.breadcrumbFor('csi.index').text, 'Storage');
    24      assert.equal(PluginDetail.breadcrumbFor('csi.plugins').text, 'Plugins');
    25      assert.equal(PluginDetail.breadcrumbFor('csi.plugins.plugin').text, plugin.id);
    26    });
    27  
    28    test('/csi/plugins/:id should show the plugin name in the title', async function(assert) {
    29      await PluginDetail.visit({ id: plugin.id });
    30  
    31      assert.equal(document.title, `CSI Plugin ${plugin.id} - Nomad`);
    32      assert.equal(PluginDetail.title, plugin.id);
    33    });
    34  
    35    test('/csi/plugins/:id should list additional details for the plugin below the title', async function(assert) {
    36      await PluginDetail.visit({ id: plugin.id });
    37  
    38      assert.ok(
    39        PluginDetail.controllerHealth.includes(
    40          `${Math.round((plugin.controllersHealthy / plugin.controllersExpected) * 100)}%`
    41        )
    42      );
    43      assert.ok(
    44        PluginDetail.controllerHealth.includes(
    45          `${plugin.controllersHealthy}/${plugin.controllersExpected}`
    46        )
    47      );
    48      assert.ok(
    49        PluginDetail.nodeHealth.includes(
    50          `${Math.round((plugin.nodesHealthy / plugin.nodesExpected) * 100)}%`
    51        )
    52      );
    53      assert.ok(PluginDetail.nodeHealth.includes(`${plugin.nodesHealthy}/${plugin.nodesExpected}`));
    54      assert.ok(PluginDetail.provider.includes(plugin.provider));
    55    });
    56  
    57    test('/csi/plugins/:id should list all the controller plugin allocations for the plugin', async function(assert) {
    58      await PluginDetail.visit({ id: plugin.id });
    59  
    60      assert.equal(PluginDetail.controllerAllocations.length, plugin.controllers.length);
    61      plugin.controllers.models
    62        .sortBy('updateTime')
    63        .reverse()
    64        .forEach((allocation, idx) => {
    65          assert.equal(PluginDetail.controllerAllocations.objectAt(idx).id, allocation.allocID);
    66        });
    67    });
    68  
    69    test('/csi/plugins/:id should list all the node plugin allocations for the plugin', async function(assert) {
    70      await PluginDetail.visit({ id: plugin.id });
    71  
    72      assert.equal(PluginDetail.nodeAllocations.length, plugin.nodes.length);
    73      plugin.nodes.models
    74        .sortBy('updateTime')
    75        .reverse()
    76        .forEach((allocation, idx) => {
    77          assert.equal(PluginDetail.nodeAllocations.objectAt(idx).id, allocation.allocID);
    78        });
    79    });
    80  
    81    test('each allocation should have high-level details for the allocation', async function(assert) {
    82      const controller = plugin.controllers.models.sortBy('updateTime').reverse()[0];
    83      const allocation = server.db.allocations.find(controller.allocID);
    84      const allocStats = server.db.clientAllocationStats.find(allocation.id);
    85      const taskGroup = server.db.taskGroups.findBy({
    86        name: allocation.taskGroup,
    87        jobId: allocation.jobId,
    88      });
    89  
    90      const tasks = taskGroup.taskIds.map(id => server.db.tasks.find(id));
    91      const cpuUsed = tasks.reduce((sum, task) => sum + task.Resources.CPU, 0);
    92      const memoryUsed = tasks.reduce((sum, task) => sum + task.Resources.MemoryMB, 0);
    93  
    94      await PluginDetail.visit({ id: plugin.id });
    95  
    96      PluginDetail.controllerAllocations.objectAt(0).as(allocationRow => {
    97        assert.equal(allocationRow.shortId, allocation.id.split('-')[0], 'Allocation short ID');
    98        assert.equal(
    99          allocationRow.createTime,
   100          moment(allocation.createTime / 1000000).format('MMM D')
   101        );
   102        assert.equal(
   103          allocationRow.createTooltip,
   104          moment(allocation.createTime / 1000000).format('MMM DD HH:mm:ss ZZ')
   105        );
   106        assert.equal(allocationRow.modifyTime, moment(allocation.modifyTime / 1000000).fromNow());
   107        assert.equal(allocationRow.health, controller.healthy ? 'Healthy' : 'Unhealthy');
   108        assert.equal(
   109          allocationRow.client,
   110          server.db.nodes.find(allocation.nodeId).id.split('-')[0],
   111          'Node ID'
   112        );
   113        assert.equal(allocationRow.job, server.db.jobs.find(allocation.jobId).name, 'Job name');
   114        assert.ok(allocationRow.taskGroup, 'Task group name');
   115        assert.ok(allocationRow.jobVersion, 'Job Version');
   116        assert.equal(
   117          allocationRow.cpu,
   118          Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
   119          'CPU %'
   120        );
   121        assert.equal(
   122          allocationRow.cpuTooltip,
   123          `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`,
   124          'Detailed CPU information is in a tooltip'
   125        );
   126        assert.equal(
   127          allocationRow.mem,
   128          allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
   129          'Memory used'
   130        );
   131        assert.equal(
   132          allocationRow.memTooltip,
   133          `${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
   134          'Detailed memory information is in a tooltip'
   135        );
   136      });
   137    });
   138  
   139    test('each allocation should link to the allocation detail page', async function(assert) {
   140      const controller = plugin.controllers.models.sortBy('updateTime').reverse()[0];
   141  
   142      await PluginDetail.visit({ id: plugin.id });
   143      await PluginDetail.controllerAllocations.objectAt(0).visit();
   144  
   145      assert.equal(currentURL(), `/allocations/${controller.allocID}`);
   146    });
   147  
   148    test('when there are no plugin allocations, the tables present empty states', async function(assert) {
   149      const emptyPlugin = server.create('csi-plugin', {
   150        controllersHealthy: 0,
   151        controllersExpected: 0,
   152        nodesHealthy: 0,
   153        nodesExpected: 0,
   154      });
   155  
   156      await PluginDetail.visit({ id: emptyPlugin.id });
   157  
   158      assert.ok(PluginDetail.controllerTableIsEmpty);
   159      assert.equal(PluginDetail.controllerEmptyState.headline, 'No Controller Plugin Allocations');
   160  
   161      assert.ok(PluginDetail.nodeTableIsEmpty);
   162      assert.equal(PluginDetail.nodeEmptyState.headline, 'No Node Plugin Allocations');
   163    });
   164  });