@@ -38,8 +38,9 @@ const MAX_32_BIT_INT = 2 ** 31 - 1;
38
38
class TestMetricExporter implements PushMetricExporter {
39
39
public exportTime = 0 ;
40
40
public forceFlushTime = 0 ;
41
- public throwException = false ;
42
- public failureResult = false ;
41
+ public throwExport = false ;
42
+ public throwFlush = false ;
43
+ public rejectExport = false ;
43
44
private _batches : ResourceMetrics [ ] = [ ] ;
44
45
private _shutdown : boolean = false ;
45
46
@@ -49,11 +50,11 @@ class TestMetricExporter implements PushMetricExporter {
49
50
) : void {
50
51
this . _batches . push ( metrics ) ;
51
52
52
- if ( this . throwException ) {
53
+ if ( this . throwExport ) {
53
54
throw new Error ( 'Error during export' ) ;
54
55
}
55
56
setTimeout ( ( ) => {
56
- if ( this . failureResult ) {
57
+ if ( this . rejectExport ) {
57
58
resultCallback ( {
58
59
code : ExportResultCode . FAILED ,
59
60
error : new Error ( 'some error' ) ,
@@ -72,7 +73,7 @@ class TestMetricExporter implements PushMetricExporter {
72
73
}
73
74
74
75
async forceFlush ( ) : Promise < void > {
75
- if ( this . throwException ) {
76
+ if ( this . throwFlush ) {
76
77
throw new Error ( 'Error during forceFlush' ) ;
77
78
}
78
79
@@ -91,6 +92,10 @@ class TestMetricExporter implements PushMetricExporter {
91
92
}
92
93
return this . _batches . slice ( 0 , numberOfExports ) ;
93
94
}
95
+
96
+ getExports ( ) : ResourceMetrics [ ] {
97
+ return this . _batches . slice ( 0 ) ;
98
+ }
94
99
}
95
100
96
101
class TestDeltaMetricExporter extends TestMetricExporter {
@@ -203,7 +208,7 @@ describe('PeriodicExportingMetricReader', () => {
203
208
describe ( 'periodic export' , ( ) => {
204
209
it ( 'should keep running on export errors' , async ( ) => {
205
210
const exporter = new TestMetricExporter ( ) ;
206
- exporter . throwException = true ;
211
+ exporter . throwExport = true ;
207
212
const reader = new PeriodicExportingMetricReader ( {
208
213
exporter : exporter ,
209
214
exportIntervalMillis : 30 ,
@@ -218,13 +223,13 @@ describe('PeriodicExportingMetricReader', () => {
218
223
emptyResourceMetrics ,
219
224
] ) ;
220
225
221
- exporter . throwException = false ;
226
+ exporter . throwExport = false ;
222
227
await reader . shutdown ( ) ;
223
228
} ) ;
224
229
225
230
it ( 'should keep running on export failure' , async ( ) => {
226
231
const exporter = new TestMetricExporter ( ) ;
227
- exporter . failureResult = true ;
232
+ exporter . rejectExport = true ;
228
233
const reader = new PeriodicExportingMetricReader ( {
229
234
exporter : exporter ,
230
235
exportIntervalMillis : 30 ,
@@ -239,7 +244,7 @@ describe('PeriodicExportingMetricReader', () => {
239
244
emptyResourceMetrics ,
240
245
] ) ;
241
246
242
- exporter . failureResult = false ;
247
+ exporter . rejectExport = false ;
243
248
await reader . shutdown ( ) ;
244
249
} ) ;
245
250
@@ -261,7 +266,7 @@ describe('PeriodicExportingMetricReader', () => {
261
266
emptyResourceMetrics ,
262
267
] ) ;
263
268
264
- exporter . throwException = false ;
269
+ exporter . throwExport = false ;
265
270
await reader . shutdown ( ) ;
266
271
} ) ;
267
272
} ) ;
@@ -271,7 +276,7 @@ describe('PeriodicExportingMetricReader', () => {
271
276
sinon . restore ( ) ;
272
277
} ) ;
273
278
274
- it ( 'should forceFlush exporter' , async ( ) => {
279
+ it ( 'should collect and forceFlush exporter' , async ( ) => {
275
280
const exporter = new TestMetricExporter ( ) ;
276
281
const exporterMock = sinon . mock ( exporter ) ;
277
282
exporterMock . expects ( 'forceFlush' ) . calledOnceWithExactly ( ) ;
@@ -284,6 +289,10 @@ describe('PeriodicExportingMetricReader', () => {
284
289
reader . setMetricProducer ( new TestMetricProducer ( ) ) ;
285
290
await reader . forceFlush ( ) ;
286
291
exporterMock . verify ( ) ;
292
+
293
+ const exports = exporter . getExports ( ) ;
294
+ assert . strictEqual ( exports . length , 1 ) ;
295
+
287
296
await reader . shutdown ( ) ;
288
297
} ) ;
289
298
@@ -307,12 +316,13 @@ describe('PeriodicExportingMetricReader', () => {
307
316
308
317
it ( 'should throw when exporter throws' , async ( ) => {
309
318
const exporter = new TestMetricExporter ( ) ;
310
- exporter . throwException = true ;
319
+ exporter . throwFlush = true ;
311
320
const reader = new PeriodicExportingMetricReader ( {
312
321
exporter : exporter ,
313
322
exportIntervalMillis : MAX_32_BIT_INT ,
314
323
exportTimeoutMillis : 80 ,
315
324
} ) ;
325
+ reader . setMetricProducer ( new TestMetricProducer ( ) ) ;
316
326
317
327
await assertRejects ( ( ) => reader . forceFlush ( ) , / E r r o r d u r i n g f o r c e F l u s h / ) ;
318
328
} ) ;
@@ -454,7 +464,7 @@ describe('PeriodicExportingMetricReader', () => {
454
464
455
465
it ( 'should throw on non-initialized instance.' , async ( ) => {
456
466
const exporter = new TestMetricExporter ( ) ;
457
- exporter . throwException = true ;
467
+ exporter . throwFlush = true ;
458
468
const reader = new PeriodicExportingMetricReader ( {
459
469
exporter : exporter ,
460
470
exportIntervalMillis : MAX_32_BIT_INT ,
0 commit comments