selectors.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { deduplicatedLogsSelector } from './selectors';
  2. import { LogsDedupStrategy } from 'app/core/logs_model';
  3. import { ExploreItemState } from 'app/types';
  4. const state = {
  5. logsResult: {
  6. rows: [
  7. {
  8. entry: '2019-03-05T11:00:56Z sntpc sntpc[1]: offset=-0.033938, delay=0.000649',
  9. },
  10. {
  11. entry: '2019-03-05T11:00:26Z sntpc sntpc[1]: offset=-0.033730, delay=0.000581',
  12. },
  13. {
  14. entry: '2019-03-05T10:59:56Z sntpc sntpc[1]: offset=-0.034184, delay=0.001089',
  15. },
  16. {
  17. entry: '2019-03-05T10:59:26Z sntpc sntpc[1]: offset=-0.033972, delay=0.000582',
  18. },
  19. {
  20. entry: '2019-03-05T10:58:56Z sntpc sntpc[1]: offset=-0.033955, delay=0.000606',
  21. },
  22. {
  23. entry: '2019-03-05T10:58:26Z sntpc sntpc[1]: offset=-0.034067, delay=0.000616',
  24. },
  25. {
  26. entry: '2019-03-05T10:57:56Z sntpc sntpc[1]: offset=-0.034155, delay=0.001021',
  27. },
  28. {
  29. entry: '2019-03-05T10:57:26Z sntpc sntpc[1]: offset=-0.035797, delay=0.000883',
  30. },
  31. {
  32. entry: '2019-03-05T10:56:56Z sntpc sntpc[1]: offset=-0.046818, delay=0.000605',
  33. },
  34. {
  35. entry: '2019-03-05T10:56:26Z sntpc sntpc[1]: offset=-0.049200, delay=0.000584',
  36. },
  37. ],
  38. },
  39. hiddenLogLevels: undefined,
  40. dedupStrategy: LogsDedupStrategy.none,
  41. };
  42. describe('Deduplication selector', () => {
  43. it('should correctly deduplicate log rows when changing strategy multiple times', () => {
  44. // Simulating sequence of UI actions that was causing a problem with deduplication counter being visible when unnecessary.
  45. // The sequence was changing dedup strategy: (none -> exact -> numbers -> signature -> none) *2 -> exact. After that the first
  46. // row contained information that was deduped, while it shouldn't be.
  47. // Problem was caused by mutating the log results entries in redux state. The memoisation hash for deduplicatedLogsSelector
  48. // was changing depending on duplicates information from log row state, while should be dependand on log row only.
  49. let dedups = deduplicatedLogsSelector(state as ExploreItemState);
  50. expect(dedups.rows.length).toBe(10);
  51. deduplicatedLogsSelector({
  52. ...state,
  53. dedupStrategy: LogsDedupStrategy.none,
  54. } as ExploreItemState);
  55. deduplicatedLogsSelector({
  56. ...state,
  57. dedupStrategy: LogsDedupStrategy.exact,
  58. } as ExploreItemState);
  59. deduplicatedLogsSelector({
  60. ...state,
  61. dedupStrategy: LogsDedupStrategy.numbers,
  62. } as ExploreItemState);
  63. deduplicatedLogsSelector({
  64. ...state,
  65. dedupStrategy: LogsDedupStrategy.signature,
  66. } as ExploreItemState);
  67. deduplicatedLogsSelector({
  68. ...state,
  69. dedupStrategy: LogsDedupStrategy.none,
  70. } as ExploreItemState);
  71. deduplicatedLogsSelector({
  72. ...state,
  73. dedupStrategy: LogsDedupStrategy.exact,
  74. } as ExploreItemState);
  75. deduplicatedLogsSelector({
  76. ...state,
  77. dedupStrategy: LogsDedupStrategy.numbers,
  78. } as ExploreItemState);
  79. deduplicatedLogsSelector({
  80. ...state,
  81. dedupStrategy: LogsDedupStrategy.signature,
  82. } as ExploreItemState);
  83. deduplicatedLogsSelector({
  84. ...state,
  85. dedupStrategy: LogsDedupStrategy.none,
  86. } as ExploreItemState);
  87. dedups = deduplicatedLogsSelector({
  88. ...state,
  89. dedupStrategy: LogsDedupStrategy.exact,
  90. } as ExploreItemState);
  91. // Expecting that no row has duplicates now
  92. expect(dedups.rows.reduce((acc, row) => acc + row.duplicates, 0)).toBe(0);
  93. });
  94. });