queuesTable.spec.tsx 4.8 KB

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