MM-58772 Change PerformanceReporter to use Date.now for timestamps (#27396)
* MM-58772 Change PerformanceReporter to use Date.now for timestamps * Let timestamps be equal in test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
efe04e31b0
Коммит
f6d0dc1931
@@ -33,9 +33,15 @@ describe('PerformanceReporter', () => {
|
|||||||
|
|
||||||
const testMarkA = performance.mark('testMarkA');
|
const testMarkA = performance.mark('testMarkA');
|
||||||
const testMarkB = performance.mark('testMarkB');
|
const testMarkB = performance.mark('testMarkB');
|
||||||
|
|
||||||
|
const timeA = Date.now();
|
||||||
measureAndReport('testMeasureA', 'testMarkA', 'testMarkB');
|
measureAndReport('testMeasureA', 'testMarkA', 'testMarkB');
|
||||||
|
|
||||||
|
await waitForObservations();
|
||||||
|
|
||||||
const testMarkC = performance.mark('testMarkC');
|
const testMarkC = performance.mark('testMarkC');
|
||||||
|
|
||||||
|
const timeBC = Date.now();
|
||||||
measureAndReport('testMeasureB', 'testMarkA', 'testMarkC');
|
measureAndReport('testMeasureB', 'testMarkA', 'testMarkC');
|
||||||
measureAndReport('testMeasureC', 'testMarkB', 'testMarkC');
|
measureAndReport('testMeasureC', 'testMarkB', 'testMarkC');
|
||||||
|
|
||||||
@@ -49,26 +55,27 @@ describe('PerformanceReporter', () => {
|
|||||||
expect(sendBeacon.mock.calls[0][0]).toEqual(siteUrl + '/api/v4/client_perf');
|
expect(sendBeacon.mock.calls[0][0]).toEqual(siteUrl + '/api/v4/client_perf');
|
||||||
const report = JSON.parse(sendBeacon.mock.calls[0][1]);
|
const report = JSON.parse(sendBeacon.mock.calls[0][1]);
|
||||||
expect(report).toMatchObject({
|
expect(report).toMatchObject({
|
||||||
start: performance.timeOrigin + testMarkA.startTime,
|
|
||||||
end: performance.timeOrigin + testMarkB.startTime,
|
|
||||||
histograms: [
|
histograms: [
|
||||||
{
|
{
|
||||||
metric: 'testMeasureA',
|
metric: 'testMeasureA',
|
||||||
value: testMarkB.startTime - testMarkA.startTime,
|
value: testMarkB.startTime - testMarkA.startTime,
|
||||||
timestamp: performance.timeOrigin + testMarkA.startTime,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
metric: 'testMeasureB',
|
metric: 'testMeasureB',
|
||||||
value: testMarkC.startTime - testMarkA.startTime,
|
value: testMarkC.startTime - testMarkA.startTime,
|
||||||
timestamp: performance.timeOrigin + testMarkA.startTime,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
metric: 'testMeasureC',
|
metric: 'testMeasureC',
|
||||||
value: testMarkC.startTime - testMarkB.startTime,
|
value: testMarkC.startTime - testMarkB.startTime,
|
||||||
timestamp: performance.timeOrigin + testMarkB.startTime,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
expect(report.start).toEqual(report.histograms[0].timestamp);
|
||||||
|
expect(report.end).toEqual(report.histograms[2].timestamp);
|
||||||
|
expect(report.histograms[0].timestamp).toBeGreaterThanOrEqual(timeA);
|
||||||
|
expect(report.histograms[0].timestamp).toBeLessThanOrEqual(timeBC);
|
||||||
|
expect(report.histograms[1].timestamp).toBeGreaterThanOrEqual(timeBC);
|
||||||
|
expect(report.histograms[2].timestamp).toBeGreaterThanOrEqual(timeBC);
|
||||||
|
|
||||||
reporter.disconnect();
|
reporter.disconnect();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export default class PerformanceReporter {
|
|||||||
this.histogramMeasures.push({
|
this.histogramMeasures.push({
|
||||||
metric: Measure.PageLoad,
|
metric: Measure.PageLoad,
|
||||||
value: entries[0].duration,
|
value: entries[0].duration,
|
||||||
timestamp: performance.timeOrigin + entries[0].startTime,
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ export default class PerformanceReporter {
|
|||||||
this.histogramMeasures.push({
|
this.histogramMeasures.push({
|
||||||
metric: entry.name,
|
metric: entry.name,
|
||||||
value: entry.duration,
|
value: entry.duration,
|
||||||
timestamp: performance.timeOrigin + entry.startTime,
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ export default class PerformanceReporter {
|
|||||||
this.histogramMeasures.push({
|
this.histogramMeasures.push({
|
||||||
metric: metric.name,
|
metric: metric.name,
|
||||||
value: metric.value,
|
value: metric.value,
|
||||||
timestamp: performance.timeOrigin + performance.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user