1
1
import { BrowserClient } from '@sentry/browser' ;
2
2
import { Hub } from '@sentry/hub' ;
3
3
4
- import { DEFAULT_IDLE_TIMEOUT , IdleTransaction , IdleTransactionSpanRecorder } from '../src/idletransaction' ;
4
+ import {
5
+ DEFAULT_IDLE_TIMEOUT ,
6
+ HEARTBEAT_INTERVAL ,
7
+ IdleTransaction ,
8
+ IdleTransactionSpanRecorder ,
9
+ } from '../src/idletransaction' ;
5
10
import { Span } from '../src/span' ;
6
11
import { SpanStatus } from '../src/spanstatus' ;
7
12
@@ -13,7 +18,7 @@ beforeEach(() => {
13
18
describe ( 'IdleTransaction' , ( ) => {
14
19
describe ( 'onScope' , ( ) => {
15
20
it ( 'sets the transaction on the scope on creation if onScope is true' , ( ) => {
16
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 , true ) ;
21
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT , true ) ;
17
22
transaction . initSpanRecorder ( 10 ) ;
18
23
19
24
hub . configureScope ( s => {
@@ -22,7 +27,7 @@ describe('IdleTransaction', () => {
22
27
} ) ;
23
28
24
29
it ( 'does not set the transaction on the scope on creation if onScope is falsey' , ( ) => {
25
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
30
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
26
31
transaction . initSpanRecorder ( 10 ) ;
27
32
28
33
hub . configureScope ( s => {
@@ -31,7 +36,7 @@ describe('IdleTransaction', () => {
31
36
} ) ;
32
37
33
38
it ( 'removes sampled transaction from scope on finish if onScope is true' , ( ) => {
34
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 , true ) ;
39
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT , true ) ;
35
40
transaction . initSpanRecorder ( 10 ) ;
36
41
37
42
transaction . finish ( ) ;
@@ -43,7 +48,7 @@ describe('IdleTransaction', () => {
43
48
} ) ;
44
49
45
50
it ( 'removes unsampled transaction from scope on finish if onScope is true' , ( ) => {
46
- const transaction = new IdleTransaction ( { name : 'foo' , sampled : false } , hub , 1000 , true ) ;
51
+ const transaction = new IdleTransaction ( { name : 'foo' , sampled : false } , hub , DEFAULT_IDLE_TIMEOUT , true ) ;
47
52
48
53
transaction . finish ( ) ;
49
54
jest . runAllTimers ( ) ;
@@ -59,7 +64,7 @@ describe('IdleTransaction', () => {
59
64
} ) ;
60
65
61
66
it ( 'push and pops activities' , ( ) => {
62
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
67
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
63
68
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
64
69
transaction . initSpanRecorder ( 10 ) ;
65
70
expect ( transaction . activities ) . toMatchObject ( { } ) ;
@@ -77,7 +82,7 @@ describe('IdleTransaction', () => {
77
82
} ) ;
78
83
79
84
it ( 'does not push activities if a span already has an end timestamp' , ( ) => {
80
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
85
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
81
86
transaction . initSpanRecorder ( 10 ) ;
82
87
expect ( transaction . activities ) . toMatchObject ( { } ) ;
83
88
@@ -86,7 +91,7 @@ describe('IdleTransaction', () => {
86
91
} ) ;
87
92
88
93
it ( 'does not finish if there are still active activities' , ( ) => {
89
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
94
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
90
95
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
91
96
transaction . initSpanRecorder ( 10 ) ;
92
97
expect ( transaction . activities ) . toMatchObject ( { } ) ;
@@ -105,7 +110,7 @@ describe('IdleTransaction', () => {
105
110
it ( 'calls beforeFinish callback before finishing' , ( ) => {
106
111
const mockCallback1 = jest . fn ( ) ;
107
112
const mockCallback2 = jest . fn ( ) ;
108
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
113
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
109
114
transaction . initSpanRecorder ( 10 ) ;
110
115
transaction . registerBeforeFinishCallback ( mockCallback1 ) ;
111
116
transaction . registerBeforeFinishCallback ( mockCallback2 ) ;
@@ -124,7 +129,7 @@ describe('IdleTransaction', () => {
124
129
} ) ;
125
130
126
131
it ( 'filters spans on finish' , ( ) => {
127
- const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , 1000 ) ;
132
+ const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , DEFAULT_IDLE_TIMEOUT ) ;
128
133
transaction . initSpanRecorder ( 10 ) ;
129
134
130
135
// regular child - should be kept
@@ -158,15 +163,15 @@ describe('IdleTransaction', () => {
158
163
159
164
describe ( '_initTimeout' , ( ) => {
160
165
it ( 'finishes if no activities are added to the transaction' , ( ) => {
161
- const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , 1000 ) ;
166
+ const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , DEFAULT_IDLE_TIMEOUT ) ;
162
167
transaction . initSpanRecorder ( 10 ) ;
163
168
164
169
jest . advanceTimersByTime ( DEFAULT_IDLE_TIMEOUT ) ;
165
170
expect ( transaction . endTimestamp ) . toBeDefined ( ) ;
166
171
} ) ;
167
172
168
173
it ( 'does not finish if a activity is started' , ( ) => {
169
- const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , 1000 ) ;
174
+ const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , DEFAULT_IDLE_TIMEOUT ) ;
170
175
transaction . initSpanRecorder ( 10 ) ;
171
176
transaction . startChild ( { } ) ;
172
177
@@ -177,7 +182,6 @@ describe('IdleTransaction', () => {
177
182
178
183
describe ( 'heartbeat' , ( ) => {
179
184
it ( 'does not mark transaction as `DeadlineExceeded` if idle timeout has not been reached' , ( ) => {
180
- const HEARTBEAT_INTERVAL = 5000 ;
181
185
// 20s to exceed 3 heartbeats
182
186
const transaction = new IdleTransaction ( { name : 'foo' } , hub , 20000 ) ;
183
187
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
@@ -202,7 +206,7 @@ describe('IdleTransaction', () => {
202
206
} ) ;
203
207
204
208
it ( 'finishes a transaction after 3 beats' , ( ) => {
205
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
209
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
206
210
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
207
211
transaction . initSpanRecorder ( 10 ) ;
208
212
@@ -223,7 +227,7 @@ describe('IdleTransaction', () => {
223
227
} ) ;
224
228
225
229
it ( 'resets after new activities are added' , ( ) => {
226
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
230
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
227
231
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
228
232
transaction . initSpanRecorder ( 10 ) ;
229
233
@@ -315,7 +319,7 @@ describe('IdleTransactionSpanRecorder', () => {
315
319
const mockPushActivity = jest . fn ( ) ;
316
320
const mockPopActivity = jest . fn ( ) ;
317
321
318
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
322
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , DEFAULT_IDLE_TIMEOUT ) ;
319
323
const spanRecorder = new IdleTransactionSpanRecorder ( mockPushActivity , mockPopActivity , transaction . spanId , 10 ) ;
320
324
321
325
spanRecorder . add ( transaction ) ;
0 commit comments