queuesTable.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import useOrganization from 'sentry/utils/useOrganization';
  4. import {QueuesTable} from 'sentry/views/performance/queues/queuesTable';
  5. import {SpanIndexedField} from 'sentry/views/starfish/types';
  6. jest.mock('sentry/utils/useOrganization');
  7. describe('queuesTable', () => {
  8. const organization = OrganizationFixture();
  9. jest.mocked(useOrganization).mockReturnValue(organization);
  10. let eventsMock;
  11. const pageLinks =
  12. '<https://sentry.io/fake/previous>; rel="previous"; results="false"; cursor="0:0:1", ' +
  13. '<https://sentry.io/fake/next>; rel="next"; results="true"; cursor="0:20:0"';
  14. beforeEach(() => {
  15. eventsMock = MockApiClient.addMockResponse({
  16. url: `/organizations/${organization.slug}/events/`,
  17. headers: {Link: pageLinks},
  18. method: 'GET',
  19. body: {
  20. data: [
  21. {
  22. 'messaging.destination.name': 'celery.backend_cleanup',
  23. 'count()': 2,
  24. 'count_op(queue.publish)': 0,
  25. 'count_op(queue.process)': 2,
  26. 'sum(span.duration)': 6,
  27. 'avg(span.duration)': 3,
  28. 'avg_if(span.duration,span.op,queue.publish)': 0,
  29. 'avg_if(span.duration,span.op,queue.process)': 3,
  30. 'avg(messaging.message.receive.latency)': 20,
  31. 'time_spent_percentage(app,span.duration)': 0.5,
  32. },
  33. ],
  34. meta: {
  35. fields: {
  36. 'count()': 'integer',
  37. 'count_op(queue.publish)': 'integer',
  38. 'count_op(queue.process)': 'integer',
  39. 'sum(span.duration)': 'duration',
  40. 'avg(span.duration)': 'duration',
  41. 'avg_if(span.duration,span.op,queue.publish)': 'duration',
  42. 'avg_if(span.duration,span.op,queue.process)': 'duration',
  43. 'avg(messaging.message.receive.latency)': 'duration',
  44. 'time_spent_percentage(app,span.duration)': 'percentage',
  45. },
  46. },
  47. },
  48. });
  49. });
  50. it('renders', async () => {
  51. render(
  52. <QueuesTable
  53. sort={{field: 'time_spent_percentage(app,span.duration)', kind: 'desc'}}
  54. />
  55. );
  56. expect(screen.getByRole('table', {name: 'Queues'})).toBeInTheDocument();
  57. expect(screen.getByRole('columnheader', {name: 'Destination'})).toBeInTheDocument();
  58. expect(
  59. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  60. ).toBeInTheDocument();
  61. expect(
  62. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  63. ).toBeInTheDocument();
  64. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  65. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  66. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  67. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  68. expect(eventsMock).toHaveBeenCalledWith(
  69. '/organizations/org-slug/events/',
  70. expect.objectContaining({
  71. query: expect.objectContaining({
  72. field: [
  73. 'messaging.destination.name',
  74. 'count()',
  75. 'count_op(queue.publish)',
  76. 'count_op(queue.process)',
  77. 'sum(span.duration)',
  78. 'avg(span.duration)',
  79. 'avg_if(span.duration,span.op,queue.publish)',
  80. 'avg_if(span.duration,span.op,queue.process)',
  81. 'avg(messaging.message.receive.latency)',
  82. 'time_spent_percentage(app,span.duration)',
  83. ],
  84. dataset: 'spansMetrics',
  85. }),
  86. })
  87. );
  88. await screen.findByText('celery.backend_cleanup');
  89. expect(screen.getByRole('cell', {name: '3.00ms'})).toBeInTheDocument();
  90. expect(screen.getByRole('cell', {name: '2'})).toBeInTheDocument();
  91. expect(screen.getByRole('cell', {name: '6.00ms'})).toBeInTheDocument();
  92. expect(screen.getByRole('cell', {name: '20.00ms'})).toBeInTheDocument();
  93. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  94. });
  95. it('searches for a destination and sorts', async () => {
  96. render(
  97. <QueuesTable
  98. destination="*events*"
  99. sort={{field: SpanIndexedField.MESSAGING_MESSAGE_DESTINATION_NAME, kind: 'desc'}}
  100. />
  101. );
  102. expect(eventsMock).toHaveBeenCalledWith(
  103. '/organizations/org-slug/events/',
  104. expect.objectContaining({
  105. query: expect.objectContaining({
  106. field: [
  107. 'messaging.destination.name',
  108. 'count()',
  109. 'count_op(queue.publish)',
  110. 'count_op(queue.process)',
  111. 'sum(span.duration)',
  112. 'avg(span.duration)',
  113. 'avg_if(span.duration,span.op,queue.publish)',
  114. 'avg_if(span.duration,span.op,queue.process)',
  115. 'avg(messaging.message.receive.latency)',
  116. 'time_spent_percentage(app,span.duration)',
  117. ],
  118. dataset: 'spansMetrics',
  119. sort: '-messaging.destination.name',
  120. query:
  121. 'span.op:[queue.process,queue.publish] messaging.destination.name:*events*',
  122. }),
  123. })
  124. );
  125. await screen.findByText('celery.backend_cleanup');
  126. });
  127. });