|
| 1 | +import { logger } from '@sentry/core'; |
| 2 | +import { _clampSpanProcessorTimeout } from '../../src/sdk/initOtel'; |
| 3 | + |
| 4 | +describe('_clampSpanProcessorTimeout', () => { |
| 5 | + beforeEach(() => { |
| 6 | + jest.clearAllMocks(); |
| 7 | + }); |
| 8 | + |
| 9 | + it('works with undefined', () => { |
| 10 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 11 | + const timeout = _clampSpanProcessorTimeout(undefined); |
| 12 | + expect(timeout).toBe(undefined); |
| 13 | + expect(loggerWarnSpy).not.toHaveBeenCalled(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('works with positive number', () => { |
| 17 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 18 | + const timeout = _clampSpanProcessorTimeout(10); |
| 19 | + expect(timeout).toBe(10); |
| 20 | + expect(loggerWarnSpy).not.toHaveBeenCalled(); |
| 21 | + }); |
| 22 | + |
| 23 | + it('works with 0', () => { |
| 24 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 25 | + const timeout = _clampSpanProcessorTimeout(0); |
| 26 | + expect(timeout).toBe(undefined); |
| 27 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 28 | + expect(loggerWarnSpy).toHaveBeenCalledWith( |
| 29 | + '`maxSpanWaitDuration` must be a positive number, using default value instead.', |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it('works with negative number', () => { |
| 34 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 35 | + const timeout = _clampSpanProcessorTimeout(-10); |
| 36 | + expect(timeout).toBe(undefined); |
| 37 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 38 | + expect(loggerWarnSpy).toHaveBeenCalledWith( |
| 39 | + '`maxSpanWaitDuration` must be a positive number, using default value instead.', |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + it('works with -Infinity', () => { |
| 44 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 45 | + const timeout = _clampSpanProcessorTimeout(-Infinity); |
| 46 | + expect(timeout).toBe(undefined); |
| 47 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 48 | + expect(loggerWarnSpy).toHaveBeenCalledWith( |
| 49 | + '`maxSpanWaitDuration` must be a positive number, using default value instead.', |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('works with Infinity', () => { |
| 54 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 55 | + const timeout = _clampSpanProcessorTimeout(Infinity); |
| 56 | + expect(timeout).toBe(1_000_000); |
| 57 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 58 | + expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('works with large number', () => { |
| 62 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 63 | + const timeout = _clampSpanProcessorTimeout(1_000_000_000); |
| 64 | + expect(timeout).toBe(1_000_000); |
| 65 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 66 | + expect(loggerWarnSpy).toHaveBeenCalledWith('`maxSpanWaitDuration` is too high, using the maximum value of 1000000'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('works with NaN', () => { |
| 70 | + const loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {}); |
| 71 | + const timeout = _clampSpanProcessorTimeout(NaN); |
| 72 | + expect(timeout).toBe(undefined); |
| 73 | + expect(loggerWarnSpy).toHaveBeenCalledTimes(1); |
| 74 | + expect(loggerWarnSpy).toHaveBeenCalledWith( |
| 75 | + '`maxSpanWaitDuration` must be a positive number, using default value instead.', |
| 76 | + ); |
| 77 | + }); |
| 78 | +}); |
0 commit comments