@@ -197,7 +197,7 @@ describe("PingType", function() {
197197
198198 ping . submit ( `test${ i } ` ) ;
199199 await testPromise ;
200-
200+
201201 assert . ok ( validatorRun ) ;
202202 }
203203 } ) ;
@@ -230,13 +230,16 @@ describe("PingType", function() {
230230 const p = ping . testBeforeNextSubmit ( async ( ) => {
231231 throw new Error ( "This should reject!" ) ;
232232 } ) ;
233-
233+
234234 ping . submit ( ) ;
235235
236236 await assert . rejects ( p ) ;
237237 } ) ;
238238
239- it ( "runs a validator: sorry" , async function ( ) {
239+ // The following test showcases the shortcomings of the current implementation
240+ // of the Ping testing API. It's disabled as it fails with the current implementation,
241+ // but it's left there for future reference.
242+ it . skip ( "the validator is not affected by recordings after submit" , async function ( ) {
240243 const ping = new PingType ( {
241244 name : "custom" ,
242245 includeClientId : true ,
@@ -253,29 +256,79 @@ describe("PingType", function() {
253256 } ) ;
254257
255258 let validatorRun = false ;
259+ const TEST_NUM_ADDITIONS = 100 ;
256260
257261 const p = ping . testBeforeNextSubmit ( async ( ) => {
258- await new Promise < void > ( resolve => {
259- setTimeout ( ( ) => resolve ( ) , 100 ) ;
260- } ) ;
262+ await new Promise ( r => setTimeout ( r , 100 ) ) ;
263+
261264 const value = await counter . testGetValue ( ) ;
262- console . log ( "!!!" , value ) ;
263- assert . strictEqual ( value , 100 ) ;
265+ assert . strictEqual ( value , undefined ) ;
264266 validatorRun = true ;
265267 } ) ;
266268 ping . submit ( "test" ) ;
267269
268- for ( let i = 0 ; i < 100 ; i ++ ) {
270+ for ( let i = 0 ; i < TEST_NUM_ADDITIONS ; i ++ ) {
269271 counter . add ( ) ;
270- Context . dispatcher . launch ( async ( ) => {
271- await new Promise < void > ( resolve => {
272- setTimeout ( ( ) => resolve ( ) , 10 ) ;
273- } ) ;
274- } ) ;
275272 }
276273
277274 await p ;
278275
276+ assert . ok ( validatorRun ) ;
277+ } ) ;
278+
279+
280+ // The following test showcases the shortcomings of the current implementation
281+ // of the Ping testing API. It's disabled as it fails with the current implementation,
282+ // but it's left there for future reference.
283+ it . skip ( "the validator real test" , async function ( ) {
284+ const ping = new PingType ( {
285+ name : "custom" ,
286+ includeClientId : true ,
287+ sendIfEmpty : false ,
288+ reasonCodes : [ "test" ]
289+ } ) ;
290+
291+ const counter = new CounterMetricType ( {
292+ category : "aCategory" ,
293+ name : "aCounterMetric" ,
294+ sendInPings : [ "custom" ] ,
295+ lifetime : Lifetime . Ping ,
296+ disabled : false
297+ } ) ;
298+
299+ const canary = new CounterMetricType ( {
300+ category : "aCategory" ,
301+ name : "canary" ,
302+ sendInPings : [ "custom" ] ,
303+ lifetime : Lifetime . Ping ,
304+ disabled : false
305+ } ) ;
306+
307+ let validatorRun = false ;
308+ const TEST_NUM_ADDITIONS = 100 ;
309+
310+ const p = ping . testBeforeNextSubmit ( async ( ) => {
311+ await new Promise ( r => setTimeout ( r , 100 ) ) ;
312+
313+ assert . strictEqual ( await counter . testGetValue ( ) , 37 , "Canary must match" ) ;
314+ const value = await counter . testGetValue ( ) ;
315+ assert . strictEqual ( value , undefined ) ;
316+ validatorRun = true ;
317+ } ) ;
318+
319+ const testFunc = ( ) => {
320+ canary . add ( 37 ) ;
321+ ping . submit ( "test" ) ;
322+ } ;
323+
324+ testFunc ( ) ;
325+
326+ await p ;
327+ for ( let i = 0 ; i < TEST_NUM_ADDITIONS ; i ++ ) {
328+ counter . add ( ) ;
329+ }
330+
331+
279332 assert . ok ( validatorRun ) ;
280333 } ) ;
281334} ) ;
0 commit comments