@@ -16,6 +16,7 @@ import {
1616} from "../src/error" ;
1717import { awaitNextTick , awaitTimeout } from "../src/util" ;
1818import { FluentSocketEvent } from "../src/socket" ;
19+ import { FluentServer } from "../src" ;
1920
2021chai . use ( chaiAsPromised ) ;
2122const expect = chai . expect ;
@@ -518,6 +519,33 @@ describe("FluentClient", () => {
518519 sinon . assert . calledTwice ( spy ) ;
519520 } ) ;
520521
522+ it ( "should allow multiple connects and disconnects in succession" , async ( ) => {
523+ const server = new FluentServer ( ) ;
524+ await server . listen ( ) ;
525+
526+ try {
527+ const client = new FluentClient ( "abc" , {
528+ socket : {
529+ port : server . port ,
530+ } ,
531+ disableAutoconnect : true ,
532+ } ) ;
533+
534+ await client . connect ( ) ;
535+ try {
536+ const firstEvent = client . emit ( "a" , { event : "foo bar" } ) ;
537+
538+ await client . disconnect ( ) ;
539+ await client . connect ( ) ;
540+ await expect ( firstEvent ) . to . eventually . be . fulfilled ;
541+ } finally {
542+ await client . shutdown ( ) ;
543+ }
544+ } finally {
545+ await server . close ( ) ;
546+ }
547+ } ) ;
548+
521549 it ( "should reject pending events after shutdown" , async ( ) => {
522550 const { client, socket} = createFluentClient ( "test" ) ;
523551 socket . isWritable = false ;
0 commit comments