@@ -18,7 +18,7 @@ describe('extraHeaders', function () {
18
18
19
19
after ( function ( done ) {
20
20
testConn . close ( )
21
- testServer . socket . close ( done )
21
+ testServer . close ( done )
22
22
} )
23
23
24
24
it ( 'should create a headerString with extra header options' , function ( done ) {
@@ -47,7 +47,7 @@ describe('frames', function () {
47
47
48
48
after ( function ( done ) {
49
49
testClient . close ( )
50
- testServer . socket . close ( done )
50
+ testServer . close ( done )
51
51
} )
52
52
53
53
it ( 'should connect to a websocket server' , function ( done ) {
@@ -198,7 +198,7 @@ describe('handshake', function () {
198
198
} )
199
199
200
200
after ( function ( done ) {
201
- testServer . socket . close ( done )
201
+ testServer . close ( done )
202
202
} )
203
203
204
204
it ( 'should work when the handshake response is followed by a WS frame' , function ( done ) {
@@ -226,6 +226,40 @@ describe('handshake', function () {
226
226
} )
227
227
} )
228
228
229
+ describe ( 'close' , function ( ) {
230
+ before ( function ( done ) {
231
+ // Create a test server and one client
232
+ testServer = ws . createServer ( function ( conn ) {
233
+ testConn = conn
234
+ } ) . listen ( TEST_PORT , function ( ) {
235
+ testClient = ws . connect ( 'ws://localhost:' + TEST_PORT , done )
236
+ } )
237
+ } )
238
+
239
+ var called = false
240
+
241
+ it ( 'should stop the server from accepting new connections' , function ( done ) {
242
+ testServer . close ( function ( ) {
243
+ called = true
244
+ } )
245
+
246
+ var newTestClient = ws . connect ( 'ws://localhost:' + TEST_PORT )
247
+ newTestClient . once ( 'error' , function ( err ) {
248
+ err . code . should . be . equal ( 'ECONNREFUSED' )
249
+ done ( )
250
+ } )
251
+ } )
252
+
253
+ it ( 'should emit close after all client connections are closed' , function ( done ) {
254
+ called . should . be . false ( )
255
+ testClient . close ( )
256
+ testServer . once ( 'close' , function ( ) {
257
+ called . should . be . true ( )
258
+ done ( )
259
+ } )
260
+ } )
261
+ } )
262
+
229
263
function getClient ( ) {
230
264
testClient . removeAllListeners ( )
231
265
return testClient
0 commit comments