Kill metrics reducer
Reviewed By: nikoant Differential Revision: D24332440 fbshipit-source-id: 0a48b25f98d93b181b622e8477a74c7ef0094816
This commit is contained in:
committed by
Facebook GitHub Bot
parent
707b8a922e
commit
41a1af33cb
@@ -10,7 +10,7 @@
|
||||
import FrescoPlugin from '../index';
|
||||
import {PersistedState, ImageEventWithId} from '../index';
|
||||
import {AndroidCloseableReferenceLeakEvent} from '../api';
|
||||
import {MetricType, Notification} from 'flipper';
|
||||
import {Notification} from 'flipper';
|
||||
import {ImagesMap} from '../ImagePool';
|
||||
|
||||
type ScanDisplayTime = {[scan_number: number]: number};
|
||||
@@ -63,227 +63,6 @@ function mockPersistedState(
|
||||
};
|
||||
}
|
||||
|
||||
test('the metric reducer for the input having regression', () => {
|
||||
const persistedState = mockPersistedState(
|
||||
[
|
||||
{
|
||||
width: 150,
|
||||
height: 150,
|
||||
},
|
||||
{
|
||||
width: 150,
|
||||
height: 150,
|
||||
},
|
||||
{
|
||||
width: 150,
|
||||
height: 150,
|
||||
},
|
||||
],
|
||||
{
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
);
|
||||
expect(FrescoPlugin.metricsReducer).toBeDefined();
|
||||
const metrics = FrescoPlugin.metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({
|
||||
WASTED_BYTES: 37500,
|
||||
});
|
||||
});
|
||||
|
||||
test('the metric reducer for the input having no regression', () => {
|
||||
const persistedState = mockPersistedState(
|
||||
[
|
||||
{
|
||||
width: 50,
|
||||
height: 10,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
],
|
||||
{
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
);
|
||||
const metricsReducer = FrescoPlugin.metricsReducer;
|
||||
expect(metricsReducer).toBeDefined();
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({
|
||||
WASTED_BYTES: 0,
|
||||
});
|
||||
});
|
||||
|
||||
test('the metric reducer for the default persisted state', () => {
|
||||
const metricsReducer = FrescoPlugin.metricsReducer;
|
||||
expect(metricsReducer).toBeDefined();
|
||||
const metrics = metricsReducer(FrescoPlugin.defaultPersistedState);
|
||||
return expect(metrics).resolves.toMatchObject({WASTED_BYTES: 0});
|
||||
});
|
||||
|
||||
test('the metric reducer with the events data but with no imageData in imagesMap ', () => {
|
||||
const persistedState = mockPersistedState(
|
||||
[
|
||||
{
|
||||
width: 50,
|
||||
height: 10,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
],
|
||||
{
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
);
|
||||
persistedState.imagesMap = {};
|
||||
const metricsReducer = FrescoPlugin.metricsReducer;
|
||||
expect(metricsReducer).toBeDefined();
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({WASTED_BYTES: 0});
|
||||
});
|
||||
|
||||
test('the metric reducer with the no viewPort data in events', () => {
|
||||
const persistedState = mockPersistedState(
|
||||
[
|
||||
{
|
||||
width: 50,
|
||||
height: 10,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
{
|
||||
width: 50,
|
||||
height: 50,
|
||||
},
|
||||
],
|
||||
{
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
);
|
||||
delete persistedState.events[0].viewport;
|
||||
const metricsReducer = FrescoPlugin.metricsReducer;
|
||||
expect(metricsReducer).toBeDefined();
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({WASTED_BYTES: 0});
|
||||
});
|
||||
test('the metric reducer with the multiple events', () => {
|
||||
const scanDisplayTime: ScanDisplayTime = {};
|
||||
scanDisplayTime[1] = 3;
|
||||
const events: Array<ImageEventWithId> = [
|
||||
{
|
||||
imageIds: ['0', '1'],
|
||||
eventId: 0,
|
||||
attribution: [],
|
||||
startTime: 1,
|
||||
endTime: 2,
|
||||
source: 'source',
|
||||
coldStart: true,
|
||||
viewport: {width: 100, height: 100, scanDisplayTime},
|
||||
},
|
||||
{
|
||||
imageIds: ['2', '3'],
|
||||
eventId: 1,
|
||||
attribution: [],
|
||||
startTime: 1,
|
||||
endTime: 2,
|
||||
source: 'source',
|
||||
coldStart: true,
|
||||
viewport: {width: 50, height: 50, scanDisplayTime},
|
||||
},
|
||||
];
|
||||
const imageSizes = [
|
||||
{
|
||||
width: 150,
|
||||
height: 150,
|
||||
},
|
||||
{
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
{
|
||||
width: 250,
|
||||
height: 250,
|
||||
},
|
||||
{
|
||||
width: 300,
|
||||
height: 300,
|
||||
},
|
||||
];
|
||||
const imagesMap = imageSizes.reduce((acc, val, index) => {
|
||||
acc[index] = {
|
||||
imageId: String(index),
|
||||
width: val.width,
|
||||
height: val.height,
|
||||
sizeBytes: 10,
|
||||
data: 'undefined',
|
||||
};
|
||||
return acc;
|
||||
}, {} as ImagesMap);
|
||||
const persistedState = {
|
||||
surfaceList: new Set<string>(),
|
||||
images: [],
|
||||
nextEventId: 0,
|
||||
events,
|
||||
imagesMap,
|
||||
closeableReferenceLeaks: [],
|
||||
isLeakTrackingEnabled: true,
|
||||
showDiskImages: false,
|
||||
};
|
||||
const metricsReducer = FrescoPlugin.metricsReducer;
|
||||
expect(metricsReducer).toBeDefined();
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({WASTED_BYTES: 160000});
|
||||
});
|
||||
|
||||
test('closeable reference metrics on empty state', () => {
|
||||
const metricsReducer: (
|
||||
persistedState: PersistedState,
|
||||
) => Promise<MetricType> = FrescoPlugin.metricsReducer;
|
||||
const persistedState = mockPersistedState();
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({CLOSEABLE_REFERENCE_LEAKS: 0});
|
||||
});
|
||||
|
||||
test('closeable reference metrics on input', () => {
|
||||
const metricsReducer: (
|
||||
persistedState: PersistedState,
|
||||
) => Promise<MetricType> = FrescoPlugin.metricsReducer;
|
||||
const closeableReferenceLeaks: Array<AndroidCloseableReferenceLeakEvent> = [
|
||||
{
|
||||
identityHashCode: 'deadbeef',
|
||||
className: 'com.facebook.imagepipeline.memory.NativeMemoryChunk',
|
||||
stacktrace: null,
|
||||
},
|
||||
{
|
||||
identityHashCode: 'f4c3b00c',
|
||||
className: 'com.facebook.flipper.SomeMemoryAbstraction',
|
||||
stacktrace: null,
|
||||
},
|
||||
];
|
||||
const persistedState = {
|
||||
...mockPersistedState(),
|
||||
closeableReferenceLeaks,
|
||||
};
|
||||
const metrics = metricsReducer(persistedState);
|
||||
return expect(metrics).resolves.toMatchObject({CLOSEABLE_REFERENCE_LEAKS: 2});
|
||||
});
|
||||
|
||||
test('notifications for leaks', () => {
|
||||
const notificationReducer: (
|
||||
persistedState: PersistedState,
|
||||
|
||||
Reference in New Issue
Block a user