@@ -13,17 +13,10 @@ describe('accessing-reql', function () {
1313
1414beforeEach ( async ( ) => {
1515connection = await r . connect ( config )
16- assert ( connection . open )
1716} )
1817
1918afterEach ( async ( ) => {
20- if ( ! connection . open ) {
21- connection = await r . connect ( config )
22- assert ( connection . open )
23- }
24-
25- await connection . close ( )
26- assert ( ! connection . open )
19+ if ( connection ) await connection . close ( )
2720} )
2821
2922it ( '`run` should throw when called without connection' , async ( ) => {
@@ -227,7 +220,16 @@ describe('accessing-reql', function () {
227220{ name :'Mino' , grownUp :false }
228221] ) . group ( 'grownUp' ) . run ( connection , { groupFormat :'raw' } )
229222
230- assert . deepEqual ( result , { '$reql_type$' :'GROUPED_DATA' , 'data' :[ [ false , [ { 'grownUp' :false , 'name' :'Luke' } , { 'grownUp' :false , 'name' :'Mino' } ] ] , [ true , [ { 'grownUp' :true , 'name' :'Michel' } , { 'grownUp' :true , 'name' :'Laurent' } , { 'grownUp' :true , 'name' :'Sophie' } ] ] ] } )
223+ assert . deepEqual ( result , {
224+ '$reql_type$' :'GROUPED_DATA' ,
225+ 'data' :[ [ false , [ { 'grownUp' :false , 'name' :'Luke' } , {
226+ 'grownUp' :false ,
227+ 'name' :'Mino'
228+ } ] ] , [ true , [ { 'grownUp' :true , 'name' :'Michel' } , { 'grownUp' :true , 'name' :'Laurent' } , {
229+ 'grownUp' :true ,
230+ 'name' :'Sophie'
231+ } ] ] ]
232+ } )
231233} )
232234
233235it ( '`profile` should work' , async function ( ) {
@@ -242,23 +244,22 @@ describe('accessing-reql', function () {
242244assert . equal ( result , true )
243245} )
244246
245- it ( '`timeout` option should work' , async function ( ) {
246- let server , port
247- try {
248- port = Math . floor ( Math . random ( ) * ( 65535 - 1025 ) + 1025 )
249-
250- server = net . createServer ( ) . listen ( port )
251-
252- connection = await r . connect ( {
247+ it ( '`timeout` option should work' , function ( done ) {
248+ const port = Math . floor ( Math . random ( ) * ( 65535 - 1025 ) + 1025 )
249+ const server = net . createServer ( ( socket ) => {
250+ setTimeout ( ( ) => {
251+ socket . destroy ( )
252+ server . close ( )
253+ done ( )
254+ } , 1000 )
255+ } ) . listen ( port , ( ) => {
256+ r . connect ( {
253257port :port ,
254258timeout :1
259+ } ) . error ( ( err ) => {
260+ assert . equal ( err . message , 'Failed to connect to localhost:' + port + ' in less than 1s.' )
255261} )
256- assert . fail ( 'should throw' )
257- } catch ( err ) {
258- await server . close ( )
259-
260- assert . equal ( err . message , 'Failed to connect to localhost:' + port + ' in less than 1s.' )
261- }
262+ } )
262263} )
263264
264265it ( '`server` should work' , async function ( ) {