Skip to content

Commit

Permalink
Add a test for null metric timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Jan 4, 2023
1 parent 3597644 commit 062497a
Showing 1 changed file with 59 additions and 3 deletions.
62 changes: 59 additions & 3 deletions src/test/unit/process-profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,14 @@ describe('profile meta processing', function () {
});

describe('visualMetrics processing', function () {
function checkVisualMetricsForThread(thread: Thread) {
const metrics = [
function checkVisualMetricsForThread(
thread: Thread,
expectedMetricMarkers?: Array<{|
name: string,
changeMarkerLength: number,
|}>
) {
const metrics = expectedMetricMarkers ?? [
{ name: 'Visual', changeMarkerLength: 7 },
{ name: 'ContentfulSpeedIndex', changeMarkerLength: 6 },
{ name: 'PerceptualSpeedIndex', changeMarkerLength: 6 },
Expand All @@ -679,7 +685,12 @@ describe('visualMetrics processing', function () {
const metricProgressMarker = thread.markers.name.find(
(name) => name === metricProgressMarkerIndex
);
expect(metricProgressMarker).toBeTruthy();

if (changeMarkerLength > 0) {
expect(metricProgressMarker).toBeTruthy();
} else {
expect(metricProgressMarker).toBeFalsy();
}

// Check the visual metric change markers.
const metricChangeMarkerIndex = thread.stringTable.indexForString(
Expand Down Expand Up @@ -736,4 +747,49 @@ describe('visualMetrics processing', function () {

checkVisualMetricsForThread(tabProcessMainThread);
});

it('does not add markers to the parent process if metric timestamps are null', function () {
const geckoProfile = createGeckoProfile();
const visualMetrics = getVisualMetrics();

// Make all the VisualProgress timestamps null on purpose.
// Flow doesn't like null because it thinks that the timestamp can't be null.
// But this is a bug on browsertime.
visualMetrics.VisualProgress = visualMetrics.VisualProgress.map(
(progress) => ({ ...progress, timestamp: (null: any) })
);
// Make only one ContentfulSpeedIndexProgress timestamp null on purpose.
// Flow doesn't like null because it thinks that the timestamp can't be null.
// But this is a bug on browsertime.
ensureExists(visualMetrics.ContentfulSpeedIndexProgress)[0].timestamp =
(null: any);

// Add the visual metrics to the profile.
geckoProfile.meta.visualMetrics = visualMetrics;
// Make sure that the visual metrics are not changed.
expect(visualMetrics.VisualProgress).toHaveLength(7);
expect(visualMetrics.ContentfulSpeedIndexProgress).toHaveLength(6);
expect(visualMetrics.PerceptualSpeedIndexProgress).toHaveLength(6);

// Processing the profile.
const processedProfile = processGeckoProfile(geckoProfile);
const parentProcessMainThread = processedProfile.threads.find(
(thread) =>
thread.name === 'GeckoMain' && thread.processType === 'default'
);

if (!parentProcessMainThread) {
throw new Error('Could not find the parent process main thread.');
}

checkVisualMetricsForThread(parentProcessMainThread, [
// Instead of 7, we should have 0 markers for Visual because we made all
// the timestamps null.
{ name: 'Visual', changeMarkerLength: 0 },
// Instead of 6, we should have 5 markers for ContentfulSpeedIndex.
{ name: 'ContentfulSpeedIndex', changeMarkerLength: 5 },
// We didn't change the PerceptualSpeedIndexProgress, so we should have 6.
{ name: 'PerceptualSpeedIndex', changeMarkerLength: 6 },
]);
});
});

0 comments on commit 062497a

Please sign in to comment.