@@ -30,7 +30,7 @@ describe('IdleTransaction', () => {
30
30
} ) ;
31
31
} ) ;
32
32
33
- it ( 'removes transaction from scope on finish if onScope is true' , ( ) => {
33
+ it ( 'removes sampled transaction from scope on finish if onScope is true' , ( ) => {
34
34
const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 , true ) ;
35
35
transaction . initSpanRecorder ( 10 ) ;
36
36
@@ -41,6 +41,17 @@ describe('IdleTransaction', () => {
41
41
expect ( s . getTransaction ( ) ) . toBe ( undefined ) ;
42
42
} ) ;
43
43
} ) ;
44
+
45
+ it ( 'removes unsampled transaction from scope on finish if onScope is true' , ( ) => {
46
+ const transaction = new IdleTransaction ( { name : 'foo' , sampled : false } , hub , 1000 , true ) ;
47
+
48
+ transaction . finish ( ) ;
49
+ jest . runAllTimers ( ) ;
50
+
51
+ hub . configureScope ( s => {
52
+ expect ( s . getTransaction ( ) ) . toBe ( undefined ) ;
53
+ } ) ;
54
+ } ) ;
44
55
} ) ;
45
56
46
57
beforeEach ( ( ) => {
@@ -150,7 +161,7 @@ describe('IdleTransaction', () => {
150
161
const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , 1000 ) ;
151
162
transaction . initSpanRecorder ( 10 ) ;
152
163
153
- jest . runTimersToTime ( DEFAULT_IDLE_TIMEOUT ) ;
164
+ jest . advanceTimersByTime ( DEFAULT_IDLE_TIMEOUT ) ;
154
165
expect ( transaction . endTimestamp ) . toBeDefined ( ) ;
155
166
} ) ;
156
167
@@ -159,28 +170,34 @@ describe('IdleTransaction', () => {
159
170
transaction . initSpanRecorder ( 10 ) ;
160
171
transaction . startChild ( { } ) ;
161
172
162
- jest . runTimersToTime ( DEFAULT_IDLE_TIMEOUT ) ;
173
+ jest . advanceTimersByTime ( DEFAULT_IDLE_TIMEOUT ) ;
163
174
expect ( transaction . endTimestamp ) . toBeUndefined ( ) ;
164
175
} ) ;
165
176
} ) ;
166
177
167
178
describe ( 'heartbeat' , ( ) => {
168
- it ( 'does not start heartbeat if there is no span recorder' , ( ) => {
169
- const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 ) ;
179
+ it ( 'does not mark transaction as `DeadlineExceeded` if idle timeout has not been reached' , ( ) => {
180
+ const HEARTBEAT_INTERVAL = 5000 ;
181
+ // 20s to exceed 3 heartbeats
182
+ const transaction = new IdleTransaction ( { name : 'foo' } , hub , 20000 ) ;
170
183
const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
171
184
185
+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
172
186
expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
173
187
174
188
// Beat 1
175
- jest . runOnlyPendingTimers ( ) ;
189
+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
190
+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
176
191
expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
177
192
178
193
// Beat 2
179
- jest . runOnlyPendingTimers ( ) ;
194
+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
195
+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
180
196
expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
181
197
182
198
// Beat 3
183
- jest . runOnlyPendingTimers ( ) ;
199
+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
200
+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
184
201
expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
185
202
} ) ;
186
203
0 commit comments