123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, waitFor} from 'sentry-test/reactTestingLibrary';
- import {HealthStatsPeriodOption} from 'sentry/types';
- import {ReleasesDisplayOption} from 'sentry/views/releases/list/releasesDisplayOptions';
- import ReleasesRequest from 'sentry/views/releases/list/releasesRequest';
- describe('ReleasesRequest', () => {
- const {organization, router} = initializeOrg();
- const projectId = 123;
- const selection = {
- projects: [projectId],
- environments: [],
- datetime: {
- period: '14d',
- start: null,
- end: null,
- utc: false,
- },
- };
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SessionStatusCountByReleaseInPeriod(),
- match: [
- MockApiClient.matchQuery({
- query:
- 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
- interval: '1d',
- statsPeriod: '14d',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project', 'release', 'session.status'],
- }),
- ],
- });
- const requestForAutoHealthStatsPeriodSessionHistogram = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SessionStatusCountByProjectInPeriod(),
- match: [
- MockApiClient.matchQuery({
- query: undefined,
- interval: '1d',
- statsPeriod: '14d',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project', 'session.status'],
- }),
- ],
- });
- const requestForAutoTotalCountByProjectInPeriod = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SessionTotalCountByProjectIn24h(),
- match: [
- MockApiClient.matchQuery({
- query: undefined,
- interval: '1d',
- statsPeriod: '14d',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project'],
- }),
- ],
- });
- const requestForAutoTotalCountByReleaseInPeriod = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SesssionTotalCountByReleaseIn24h(),
- match: [
- MockApiClient.matchQuery({
- query:
- 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
- interval: '1d',
- statsPeriod: '14d',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project', 'release'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/sessions/`,
- body: TestStubs.SesssionTotalCountByReleaseIn24h(),
- match: [
- MockApiClient.matchQuery({
- query:
- 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
- interval: '1h',
- statsPeriod: '24h',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project', 'release'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SessionTotalCountByProjectIn24h(),
- match: [
- MockApiClient.matchQuery({
- query: undefined,
- interval: '1h',
- statsPeriod: '24h',
- project: [`${projectId}`],
- field: ['sum(session)'],
- groupBy: ['project'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.SessionUserStatusCountByReleaseInPeriod(),
- match: [
- MockApiClient.matchQuery({
- query:
- 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
- interval: '1d',
- statsPeriod: '14d',
- project: [`${projectId}`],
- field: ['count_unique(user)', 'sum(session)'],
- groupBy: ['project', 'release', 'session.status'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/sessions/`,
- body: TestStubs.UserTotalCountByReleaseIn24h(),
- match: [
- MockApiClient.matchQuery({
- query:
- 'release:7a82c130be9143361f20bc77252df783cf91e4fc OR release:e102abb2c46e7fe8686441091005c12aed90da99',
- interval: '1h',
- statsPeriod: '24h',
- project: [`${projectId}`],
- field: ['count_unique(user)'],
- groupBy: ['project', 'release'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/sessions/`,
- body: TestStubs.UserTotalCountByProjectIn24h(),
- match: [
- MockApiClient.matchQuery({
- query: undefined,
- interval: '1h',
- statsPeriod: '24h',
- project: [`${projectId}`],
- field: ['count_unique(user)'],
- groupBy: ['project'],
- }),
- ],
- });
- it('calculates correct session health data', async () => {
- let healthData;
- render(
- <ReleasesRequest
- releases={[
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- ]}
- organization={organization}
- location={{
- ...router.location,
- query: {
- project: [`${projectId}`],
- },
- }}
- display={[ReleasesDisplayOption.SESSIONS]}
- selection={selection}
- >
- {({getHealthData}) => {
- healthData = getHealthData;
- return null;
- }}
- </ReleasesRequest>
- );
- await waitFor(() =>
- expect(
- healthData.getCrashCount(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(492)
- );
- expect(
- healthData.getCrashFreeRate(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(99.76);
- expect(
- healthData.get24hCountByRelease(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(219826);
- expect(
- healthData.get24hCountByProject(projectId, ReleasesDisplayOption.SESSIONS)
- ).toBe(835965);
- expect(
- healthData.getTimeSeries(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toEqual([
- {
- data: [
- {name: 1615975200000, value: 0},
- {name: 1615978800000, value: 0},
- {name: 1615982400000, value: 0},
- {name: 1615986000000, value: 0},
- {name: 1615989600000, value: 0},
- {name: 1615993200000, value: 0},
- {name: 1615996800000, value: 0},
- {name: 1616000400000, value: 0},
- {name: 1616004000000, value: 0},
- {name: 1616007600000, value: 0},
- {name: 1616011200000, value: 0},
- {name: 1616014800000, value: 0},
- {name: 1616018400000, value: 0},
- {name: 1616022000000, value: 3444},
- {name: 1616025600000, value: 14912},
- {name: 1616029200000, value: 15649},
- {name: 1616032800000, value: 18019},
- {name: 1616036400000, value: 16726},
- {name: 1616040000000, value: 17540},
- {name: 1616043600000, value: 16970},
- {name: 1616047200000, value: 25015},
- {name: 1616050800000, value: 34686},
- {name: 1616054400000, value: 46434},
- {name: 1616058000000, value: 10431},
- ],
- seriesName: 'This Release',
- },
- {
- data: [
- {name: 1615975200000, value: 51284},
- {name: 1615978800000, value: 43820},
- {name: 1615982400000, value: 46981},
- {name: 1615986000000, value: 56929},
- {name: 1615989600000, value: 59999},
- {name: 1615993200000, value: 60476},
- {name: 1615996800000, value: 54145},
- {name: 1616000400000, value: 52642},
- {name: 1616004000000, value: 42917},
- {name: 1616007600000, value: 35787},
- {name: 1616011200000, value: 35036},
- {name: 1616014800000, value: 29287},
- {name: 1616018400000, value: 24815},
- {name: 1616022000000, value: 19815},
- {name: 1616025600000, value: 16334},
- {name: 1616029200000, value: 16415},
- {name: 1616032800000, value: 18961},
- {name: 1616036400000, value: 17512},
- {name: 1616040000000, value: 18149},
- {name: 1616043600000, value: 17585},
- {name: 1616047200000, value: 25725},
- {name: 1616050800000, value: 36365},
- {name: 1616054400000, value: 48104},
- {name: 1616058000000, value: 6882},
- ],
- seriesName: 'Total Project',
- z: 0,
- },
- ]);
- expect(
- healthData.getAdoption(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(26.29607698886915);
- expect(
- healthData.getCrashCount(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(5);
- expect(
- healthData.getCrashFreeRate(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(99.921);
- expect(
- healthData.get24hCountByRelease(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(6320);
- expect(
- healthData.get24hCountByProject(projectId, ReleasesDisplayOption.SESSIONS)
- ).toBe(835965);
- expect(
- healthData.getTimeSeries(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toEqual([
- {
- data: [
- {name: 1615975200000, value: 0},
- {name: 1615978800000, value: 0},
- {name: 1615982400000, value: 0},
- {name: 1615986000000, value: 0},
- {name: 1615989600000, value: 0},
- {name: 1615993200000, value: 0},
- {name: 1615996800000, value: 0},
- {name: 1616000400000, value: 0},
- {name: 1616004000000, value: 0},
- {name: 1616007600000, value: 0},
- {name: 1616011200000, value: 0},
- {name: 1616014800000, value: 0},
- {name: 1616018400000, value: 0},
- {name: 1616022000000, value: 5809},
- {name: 1616025600000, value: 400},
- {name: 1616029200000, value: 22},
- {name: 1616032800000, value: 26},
- {name: 1616036400000, value: 12},
- {name: 1616040000000, value: 19},
- {name: 1616043600000, value: 8},
- {name: 1616047200000, value: 0},
- {name: 1616050800000, value: 19},
- {name: 1616054400000, value: 5},
- {name: 1616058000000, value: 0},
- ],
- seriesName: 'This Release',
- },
- {
- data: [
- {name: 1615975200000, value: 51284},
- {name: 1615978800000, value: 43820},
- {name: 1615982400000, value: 46981},
- {name: 1615986000000, value: 56929},
- {name: 1615989600000, value: 59999},
- {name: 1615993200000, value: 60476},
- {name: 1615996800000, value: 54145},
- {name: 1616000400000, value: 52642},
- {name: 1616004000000, value: 42917},
- {name: 1616007600000, value: 35787},
- {name: 1616011200000, value: 35036},
- {name: 1616014800000, value: 29287},
- {name: 1616018400000, value: 24815},
- {name: 1616022000000, value: 19815},
- {name: 1616025600000, value: 16334},
- {name: 1616029200000, value: 16415},
- {name: 1616032800000, value: 18961},
- {name: 1616036400000, value: 17512},
- {name: 1616040000000, value: 18149},
- {name: 1616043600000, value: 17585},
- {name: 1616047200000, value: 25725},
- {name: 1616050800000, value: 36365},
- {name: 1616054400000, value: 48104},
- {name: 1616058000000, value: 6882},
- ],
- seriesName: 'Total Project',
- z: 0,
- },
- ]);
- expect(
- healthData.getAdoption(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(0.7560125124855706);
- expect(requestForAutoHealthStatsPeriodSessionHistogram).toHaveBeenCalledTimes(0);
- });
- it('calculates correct user health data', async () => {
- let healthData;
- render(
- <ReleasesRequest
- releases={[
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- ]}
- organization={organization}
- location={{
- ...router.location,
- query: {
- project: [`${projectId}`],
- },
- }}
- display={[ReleasesDisplayOption.USERS]}
- selection={selection}
- >
- {({getHealthData}) => {
- healthData = getHealthData;
- return null;
- }}
- </ReleasesRequest>
- );
- await waitFor(() =>
- expect(
- healthData.getCrashCount(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(492)
- );
- expect(
- healthData.getCrashFreeRate(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(99.908);
- expect(
- healthData.get24hCountByRelease(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(56826);
- expect(healthData.get24hCountByProject(projectId, ReleasesDisplayOption.USERS)).toBe(
- 140965
- );
- expect(
- healthData.getTimeSeries(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toEqual([
- {
- data: [
- {name: 1615975200000, value: 0},
- {name: 1615978800000, value: 0},
- {name: 1615982400000, value: 0},
- {name: 1615986000000, value: 0},
- {name: 1615989600000, value: 0},
- {name: 1615993200000, value: 0},
- {name: 1615996800000, value: 0},
- {name: 1616000400000, value: 0},
- {name: 1616004000000, value: 0},
- {name: 1616007600000, value: 0},
- {name: 1616011200000, value: 0},
- {name: 1616014800000, value: 0},
- {name: 1616018400000, value: 0},
- {name: 1616022000000, value: 444},
- {name: 1616025600000, value: 4912},
- {name: 1616029200000, value: 5649},
- {name: 1616032800000, value: 8019},
- {name: 1616036400000, value: 6726},
- {name: 1616040000000, value: 7540},
- {name: 1616043600000, value: 6970},
- {name: 1616047200000, value: 5015},
- {name: 1616050800000, value: 4686},
- {name: 1616054400000, value: 6434},
- {name: 1616058000000, value: 431},
- ],
- seriesName: 'This Release',
- },
- {
- data: [
- {name: 1615975200000, value: 1284},
- {name: 1615978800000, value: 3820},
- {name: 1615982400000, value: 6981},
- {name: 1615986000000, value: 6929},
- {name: 1615989600000, value: 9999},
- {name: 1615993200000, value: 1476},
- {name: 1615996800000, value: 4145},
- {name: 1616000400000, value: 2642},
- {name: 1616004000000, value: 2917},
- {name: 1616007600000, value: 5787},
- {name: 1616011200000, value: 5036},
- {name: 1616014800000, value: 9287},
- {name: 1616018400000, value: 4815},
- {name: 1616022000000, value: 9815},
- {name: 1616025600000, value: 6334},
- {name: 1616029200000, value: 6415},
- {name: 1616032800000, value: 8961},
- {name: 1616036400000, value: 7512},
- {name: 1616040000000, value: 8149},
- {name: 1616043600000, value: 7585},
- {name: 1616047200000, value: 5725},
- {name: 1616050800000, value: 6365},
- {name: 1616054400000, value: 8104},
- {name: 1616058000000, value: 882},
- ],
- seriesName: 'Total Project',
- z: 0,
- },
- ]);
- expect(
- healthData.getAdoption(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(40.31213421771362);
- expect(
- healthData.getCrashCount(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(5);
- expect(
- healthData.getCrashFreeRate(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(99.87);
- expect(
- healthData.get24hCountByRelease(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(850);
- expect(healthData.get24hCountByProject(projectId, ReleasesDisplayOption.USERS)).toBe(
- 140965
- );
- expect(
- healthData.getTimeSeries(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toEqual([
- {
- data: [
- {name: 1615975200000, value: 0},
- {name: 1615978800000, value: 0},
- {name: 1615982400000, value: 0},
- {name: 1615986000000, value: 0},
- {name: 1615989600000, value: 0},
- {name: 1615993200000, value: 0},
- {name: 1615996800000, value: 0},
- {name: 1616000400000, value: 0},
- {name: 1616004000000, value: 0},
- {name: 1616007600000, value: 0},
- {name: 1616011200000, value: 0},
- {name: 1616014800000, value: 0},
- {name: 1616018400000, value: 0},
- {name: 1616022000000, value: 809},
- {name: 1616025600000, value: 0},
- {name: 1616029200000, value: 2},
- {name: 1616032800000, value: 6},
- {name: 1616036400000, value: 2},
- {name: 1616040000000, value: 9},
- {name: 1616043600000, value: 8},
- {name: 1616047200000, value: 0},
- {name: 1616050800000, value: 9},
- {name: 1616054400000, value: 5},
- {name: 1616058000000, value: 0},
- ],
- seriesName: 'This Release',
- },
- {
- data: [
- {name: 1615975200000, value: 1284},
- {name: 1615978800000, value: 3820},
- {name: 1615982400000, value: 6981},
- {name: 1615986000000, value: 6929},
- {name: 1615989600000, value: 9999},
- {name: 1615993200000, value: 1476},
- {name: 1615996800000, value: 4145},
- {name: 1616000400000, value: 2642},
- {name: 1616004000000, value: 2917},
- {name: 1616007600000, value: 5787},
- {name: 1616011200000, value: 5036},
- {name: 1616014800000, value: 9287},
- {name: 1616018400000, value: 4815},
- {name: 1616022000000, value: 9815},
- {name: 1616025600000, value: 6334},
- {name: 1616029200000, value: 6415},
- {name: 1616032800000, value: 8961},
- {name: 1616036400000, value: 7512},
- {name: 1616040000000, value: 8149},
- {name: 1616043600000, value: 7585},
- {name: 1616047200000, value: 5725},
- {name: 1616050800000, value: 6365},
- {name: 1616054400000, value: 8104},
- {name: 1616058000000, value: 882},
- ],
- seriesName: 'Total Project',
- z: 0,
- },
- ]);
- expect(
- healthData.getAdoption(
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- projectId,
- ReleasesDisplayOption.USERS
- )
- ).toBe(0.6029865569467598);
- });
- it('calculates correct session count histogram (auto period)', async () => {
- let healthData;
- render(
- <ReleasesRequest
- releases={[
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- 'e102abb2c46e7fe8686441091005c12aed90da99',
- ]}
- organization={organization}
- location={{
- ...router.location,
- query: {
- project: [`${projectId}`],
- },
- }}
- display={[ReleasesDisplayOption.SESSIONS]}
- selection={selection}
- healthStatsPeriod={HealthStatsPeriodOption.AUTO}
- >
- {({getHealthData}) => {
- healthData = getHealthData;
- return null;
- }}
- </ReleasesRequest>
- );
- await waitFor(() =>
- expect(
- healthData.getAdoption(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toBe(26.29607698886915)
- );
- expect(
- healthData.getTimeSeries(
- '7a82c130be9143361f20bc77252df783cf91e4fc',
- projectId,
- ReleasesDisplayOption.SESSIONS
- )
- ).toEqual([
- {
- data: [
- {name: 1614902400000, value: 0},
- {name: 1614988800000, value: 0},
- {name: 1615075200000, value: 0},
- {name: 1615161600000, value: 0},
- {name: 1615248000000, value: 0},
- {name: 1615334400000, value: 0},
- {name: 1615420800000, value: 0},
- {name: 1615507200000, value: 0},
- {name: 1615593600000, value: 0},
- {name: 1615680000000, value: 0},
- {name: 1615766400000, value: 0},
- {name: 1615852800000, value: 0},
- {name: 1615939200000, value: 3446},
- {name: 1616025600000, value: 201136},
- ],
- seriesName: 'This Release',
- },
- {
- data: [
- {name: 1614902400000, value: 0},
- {name: 1614988800000, value: 0},
- {name: 1615075200000, value: 0},
- {name: 1615161600000, value: 0},
- {name: 1615248000000, value: 0},
- {name: 1615334400000, value: 0},
- {name: 1615420800000, value: 0},
- {name: 1615507200000, value: 0},
- {name: 1615593600000, value: 0},
- {name: 1615680000000, value: 0},
- {name: 1615766400000, value: 0},
- {name: 1615852800000, value: 0},
- {name: 1615939200000, value: 9268},
- {name: 1616025600000, value: 1083},
- ],
- seriesName: 'Total Project',
- z: 0,
- },
- ]);
- expect(requestForAutoHealthStatsPeriodSessionHistogram).toHaveBeenCalledTimes(1);
- expect(requestForAutoTotalCountByProjectInPeriod).toHaveBeenCalledTimes(1);
- expect(requestForAutoTotalCountByReleaseInPeriod).toHaveBeenCalledTimes(1);
- });
- });
|