queuesTable.spec.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. 'trace_status_rate(ok)': 0.8,
  32. 'time_spent_percentage(app,span.duration)': 0.5,
  33. },
  34. ],
  35. meta: {
  36. fields: {
  37. 'count()': 'integer',
  38. 'count_op(queue.publish)': 'integer',
  39. 'count_op(queue.process)': 'integer',
  40. 'sum(span.duration)': 'duration',
  41. 'avg(span.duration)': 'duration',
  42. 'avg_if(span.duration,span.op,queue.publish)': 'duration',
  43. 'avg_if(span.duration,span.op,queue.process)': 'duration',
  44. 'avg(messaging.message.receive.latency)': 'duration',
  45. 'trace_status_rate(ok)': 'percentage',
  46. 'time_spent_percentage(app,span.duration)': 'percentage',
  47. },
  48. },
  49. },
  50. });
  51. });
  52. it('renders', async () => {
  53. render(
  54. <QueuesTable
  55. sort={{field: 'time_spent_percentage(app,span.duration)', kind: 'desc'}}
  56. />
  57. );
  58. expect(screen.getByRole('table', {name: 'Queues'})).toBeInTheDocument();
  59. expect(screen.getByRole('columnheader', {name: 'Destination'})).toBeInTheDocument();
  60. expect(
  61. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  62. ).toBeInTheDocument();
  63. expect(
  64. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  65. ).toBeInTheDocument();
  66. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  67. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  68. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  69. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  70. expect(eventsMock).toHaveBeenCalledWith(
  71. '/organizations/org-slug/events/',
  72. expect.objectContaining({
  73. query: expect.objectContaining({
  74. field: [
  75. 'messaging.destination.name',
  76. 'count()',
  77. 'count_op(queue.publish)',
  78. 'count_op(queue.process)',
  79. 'sum(span.duration)',
  80. 'avg(span.duration)',
  81. 'avg_if(span.duration,span.op,queue.publish)',
  82. 'avg_if(span.duration,span.op,queue.process)',
  83. 'avg(messaging.message.receive.latency)',
  84. 'trace_status_rate(ok)',
  85. 'time_spent_percentage(app,span.duration)',
  86. ],
  87. dataset: 'spansMetrics',
  88. }),
  89. })
  90. );
  91. await screen.findByText('celery.backend_cleanup');
  92. expect(screen.getByRole('cell', {name: '3.00ms'})).toBeInTheDocument();
  93. expect(screen.getByRole('cell', {name: '2'})).toBeInTheDocument();
  94. expect(screen.getByRole('cell', {name: '6.00ms'})).toBeInTheDocument();
  95. expect(screen.getByRole('cell', {name: '20.00ms'})).toBeInTheDocument();
  96. expect(screen.getByRole('cell', {name: '20%'})).toBeInTheDocument();
  97. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  98. });
  99. it('searches for a destination and sorts', async () => {
  100. render(
  101. <QueuesTable
  102. destination="*events*"
  103. sort={{field: SpanIndexedField.MESSAGING_MESSAGE_DESTINATION_NAME, kind: 'desc'}}
  104. />
  105. );
  106. expect(eventsMock).toHaveBeenCalledWith(
  107. '/organizations/org-slug/events/',
  108. expect.objectContaining({
  109. query: expect.objectContaining({
  110. field: [
  111. 'messaging.destination.name',
  112. 'count()',
  113. 'count_op(queue.publish)',
  114. 'count_op(queue.process)',
  115. 'sum(span.duration)',
  116. 'avg(span.duration)',
  117. 'avg_if(span.duration,span.op,queue.publish)',
  118. 'avg_if(span.duration,span.op,queue.process)',
  119. 'avg(messaging.message.receive.latency)',
  120. 'trace_status_rate(ok)',
  121. 'time_spent_percentage(app,span.duration)',
  122. ],
  123. dataset: 'spansMetrics',
  124. sort: '-messaging.destination.name',
  125. query:
  126. 'span.op:[queue.process,queue.publish] messaging.destination.name:*events*',
  127. }),
  128. })
  129. );
  130. await screen.findByText('celery.backend_cleanup');
  131. });
  132. });