@@ -30,7 +30,7 @@ describe('IdleTransaction', () => {
3030 } ) ;
3131 } ) ;
3232
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' , ( ) => {
3434 const transaction = new IdleTransaction ( { name : 'foo' } , hub , 1000 , true ) ;
3535 transaction . initSpanRecorder ( 10 ) ;
3636
@@ -41,6 +41,17 @@ describe('IdleTransaction', () => {
4141 expect ( s . getTransaction ( ) ) . toBe ( undefined ) ;
4242 } ) ;
4343 } ) ;
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+ } ) ;
4455 } ) ;
4556
4657 beforeEach ( ( ) => {
@@ -150,7 +161,7 @@ describe('IdleTransaction', () => {
150161 const transaction = new IdleTransaction ( { name : 'foo' , startTimestamp : 1234 } , hub , 1000 ) ;
151162 transaction . initSpanRecorder ( 10 ) ;
152163
153- jest . runTimersToTime ( DEFAULT_IDLE_TIMEOUT ) ;
164+ jest . advanceTimersByTime ( DEFAULT_IDLE_TIMEOUT ) ;
154165 expect ( transaction . endTimestamp ) . toBeDefined ( ) ;
155166 } ) ;
156167
@@ -159,28 +170,34 @@ describe('IdleTransaction', () => {
159170 transaction . initSpanRecorder ( 10 ) ;
160171 transaction . startChild ( { } ) ;
161172
162- jest . runTimersToTime ( DEFAULT_IDLE_TIMEOUT ) ;
173+ jest . advanceTimersByTime ( DEFAULT_IDLE_TIMEOUT ) ;
163174 expect ( transaction . endTimestamp ) . toBeUndefined ( ) ;
164175 } ) ;
165176 } ) ;
166177
167178 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 ) ;
170183 const mockFinish = jest . spyOn ( transaction , 'finish' ) ;
171184
185+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
172186 expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
173187
174188 // Beat 1
175- jest . runOnlyPendingTimers ( ) ;
189+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
190+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
176191 expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
177192
178193 // Beat 2
179- jest . runOnlyPendingTimers ( ) ;
194+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
195+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
180196 expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
181197
182198 // Beat 3
183- jest . runOnlyPendingTimers ( ) ;
199+ jest . advanceTimersByTime ( HEARTBEAT_INTERVAL ) ;
200+ expect ( transaction . status ) . not . toEqual ( SpanStatus . DeadlineExceeded ) ;
184201 expect ( mockFinish ) . toHaveBeenCalledTimes ( 0 ) ;
185202 } ) ;
186203
0 commit comments