From 86706e8b531d22de0df6eac6da265bd5f67b3e5c Mon Sep 17 00:00:00 2001 From: Brandon Kobel Date: Thu, 18 Oct 2018 16:16:06 -0700 Subject: [PATCH] Fix profile_tree tests (#24158) (#24238) --- .../profile_tree/__tests__/fixtures/breakdown.js | 10 +++++----- .../public/directives/profile_tree/util.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/searchprofiler/public/directives/profile_tree/__tests__/fixtures/breakdown.js b/x-pack/plugins/searchprofiler/public/directives/profile_tree/__tests__/fixtures/breakdown.js index 3d5c53ca5a5666..1d88310dafbfd6 100644 --- a/x-pack/plugins/searchprofiler/public/directives/profile_tree/__tests__/fixtures/breakdown.js +++ b/x-pack/plugins/searchprofiler/public/directives/profile_tree/__tests__/fixtures/breakdown.js @@ -63,14 +63,14 @@ export const normalized = [ { key: 'next_doc', relative: 0, color: '#f5f5f5', tip: '' }, + { key: 'match', + time: 0, + relative: '0.0', + color: '#f5f5f5', + tip: 'The time taken to execute a secondary, more precise scoring phase (used by phrase queries).' }, { key: 'match_count', time: 0, relative: 0, color: '#f5f5f5', tip: '' }, - { key: 'match', - time: 0, - relative: '0.0', - color: '#f5f5f5', - tip: 'The time taken to execute a secondary, more precise scoring phase (used by phrase queries).' } ]; diff --git a/x-pack/plugins/searchprofiler/public/directives/profile_tree/util.js b/x-pack/plugins/searchprofiler/public/directives/profile_tree/util.js index 6ed0e606f52ee4..6190d299dcf10d 100644 --- a/x-pack/plugins/searchprofiler/public/directives/profile_tree/util.js +++ b/x-pack/plugins/searchprofiler/public/directives/profile_tree/util.js @@ -84,7 +84,7 @@ export function normalizeBreakdown(breakdown) { } return partialTotal; }, 0); - Object.keys(breakdown).forEach(key => { + Object.keys(breakdown).sort().forEach(key => { let relative = 0; if (key.indexOf('_count') === -1) { relative = ((breakdown[key] / total) * 100).toFixed(1); @@ -97,8 +97,15 @@ export function normalizeBreakdown(breakdown) { tip: getToolTip(key) }); }); - final.sort((a, b) => comparator(a.time, b.time)); - return final; + + // Sort by time descending and then key ascending + return final.sort((a, b) => { + if (comparator(a.time, b.time) !== 0) { + return comparator(a.time, b.time); + } + + return -1 * comparator(a.key, b.key); + }); } export function normalizeTimes(data, totalTime, depth) {