@@ -7,6 +7,7 @@ import assert = require('assert')
7
7
describe ( 'codeDiffTracker' , ( ) => {
8
8
let codeDiffTracker : CodeDiffTracker
9
9
let mockRecordMetric : sinon . SinonStub
10
+ let testFeatures : TestFeatures
10
11
const flushInterval = 1000
11
12
const timeElapsedThreshold = 5000
12
13
const maxQueueSize = 3
@@ -16,8 +17,8 @@ describe('codeDiffTracker', () => {
16
17
now : 0 ,
17
18
shouldAdvanceTime : false ,
18
19
} )
19
- const testFeatures = new TestFeatures ( )
20
- mockRecordMetric = sinon . stub ( )
20
+ testFeatures = new TestFeatures ( )
21
+ mockRecordMetric = sinon . stub ( ) . rejects ( true )
21
22
codeDiffTracker = new CodeDiffTracker ( testFeatures . workspace , testFeatures . logging , mockRecordMetric , {
22
23
flushInterval,
23
24
timeElapsedThreshold,
@@ -27,6 +28,7 @@ describe('codeDiffTracker', () => {
27
28
} )
28
29
29
30
afterEach ( ( ) => {
31
+ testFeatures . dispose ( )
30
32
sinon . clock . restore ( )
31
33
sinon . restore ( )
32
34
} )
@@ -136,4 +138,54 @@ describe('codeDiffTracker', () => {
136
138
137
139
assert . strictEqual ( mockRecordMetric . callCount , maxQueueSize )
138
140
} )
141
+
142
+ it ( 'shutdown should catch exceptions in report handler' , async ( ) => {
143
+ const mockRecordMetric = sinon . stub ( ) . rejects ( 'Record metric rejection' )
144
+ const codeDiffTracker = new CodeDiffTracker ( testFeatures . workspace , testFeatures . logging , mockRecordMetric , {
145
+ flushInterval,
146
+ timeElapsedThreshold,
147
+ maxQueueSize,
148
+ } )
149
+
150
+ const mockEntry = {
151
+ startPosition : {
152
+ line : 0 ,
153
+ character : 0 ,
154
+ } ,
155
+ endPosition : {
156
+ line : 20 ,
157
+ character : 0 ,
158
+ } ,
159
+ fileUrl : 'test.cs' ,
160
+ // fake timer starts at 0
161
+ time : - timeElapsedThreshold ,
162
+ originalString : "console.log('test console')" ,
163
+ }
164
+
165
+ // use negative time so we don't have to move the timer which would cause the interval to run
166
+ codeDiffTracker . enqueue ( mockEntry )
167
+
168
+ codeDiffTracker . enqueue ( {
169
+ startPosition : {
170
+ line : 0 ,
171
+ character : 0 ,
172
+ } ,
173
+ endPosition : {
174
+ line : 20 ,
175
+ character : 0 ,
176
+ } ,
177
+ fileUrl : 'test.cs' ,
178
+ // fake timer starts at 0
179
+ time : - timeElapsedThreshold + 100 ,
180
+ originalString : "console.log('test console')" ,
181
+ } )
182
+
183
+ await codeDiffTracker . shutdown ( )
184
+ sinon . assert . calledOnce ( mockRecordMetric )
185
+ sinon . assert . calledWith ( mockRecordMetric , mockEntry , sinon . match . number )
186
+
187
+ assert (
188
+ testFeatures . logging . log . calledWithMatch ( 'Exception Thrown from CodeDiffTracker: Record metric rejection' )
189
+ )
190
+ } )
139
191
} )
0 commit comments