@@ -4,6 +4,7 @@ const { channel } = require('../src/helpers/instrument')
44const agent = require ( '../../dd-trace/test/plugins/agent' )
55const { assert } = require ( 'chai' )
66const semver = require ( 'semver' )
7+ const { once } = require ( 'events' )
78
89describe ( 'mysql2 instrumentation' , ( ) => {
910 withVersions ( 'mysql2' , 'mysql2' , version => {
@@ -435,16 +436,18 @@ describe('mysql2 instrumentation', () => {
435436 query . on ( 'end' , ( ) => done ( ) )
436437 } )
437438
438- it ( 'should work without abortController.abort()' , ( done ) => {
439+ it ( 'should work without abortController.abort()' , async ( ) => {
439440 startCh . subscribe ( noop )
440441 const query = pool . query ( sql )
441442
442- query . on ( 'error' , err => done ( err ) )
443- query . on ( 'end ' , ( ) => {
444- sinon . assert . called ( apmQueryStart )
443+ let error
444+ query . on ( 'error ' , err => { error = err } )
445+ expect ( query . listenerCount ( 'error' ) ) . to . equal ( 1 )
445446
446- done ( )
447- } )
447+ await once ( query , 'end' )
448+ expect ( query . listenerCount ( 'error' ) ) . to . equal ( 1 )
449+ sinon . assert . called ( apmQueryStart )
450+ expect ( error ) . to . be . undefined
448451 } )
449452
450453 it ( 'should work without subscriptions' , ( done ) => {
0 commit comments