From 3ab170614547648e0445820d85cbbc7602522da9 Mon Sep 17 00:00:00 2001 From: Joey <90795735+joey-grafana@users.noreply.github.com> Date: Tue, 16 May 2023 11:19:23 +0100 Subject: [PATCH] TraceView: Fix flaky test (#68518) Fix flaky test --- .../VirtualizedTraceView.test.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx index 5d168086483..3fdbbc1d519 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx @@ -17,6 +17,7 @@ import React from 'react'; import traceGenerator from '../demo/trace-generators'; import transformTraceData from '../model/transform-trace-data'; import { Trace } from '../types'; +import { formatDuration } from '../utils/date'; import SpanTreeOffset from './SpanTreeOffset'; import VirtualizedTraceView, { VirtualizedTraceViewProps } from './VirtualizedTraceView'; @@ -69,15 +70,8 @@ describe('', () => { expect(screen.getAllByText(trace.spans[0].operationName)).toBeTruthy(); expect(screen.getAllByText(trace.spans[1].operationName)).toBeTruthy(); - let durationSpan0 = trace.spans[0].duration; - - if (trace.spans[0].duration >= 1_000_000) { - durationSpan0 = Math.floor(trace.spans[0].duration / 1000000); - } else if (trace.spans[0].duration >= 1000) { - durationSpan0 = Math.floor(trace.spans[0].duration / 1000); - } - - expect(screen.getAllByText(durationSpan0, { exact: false })).toBeTruthy(); + let durationSpan = formatDuration(trace.spans[0].duration); + expect(screen.getAllByText(durationSpan)).toBeTruthy(); }); it('renders without exploding', () => {