File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as pg from "pg";
44import { setupPrimary } from "../../lib/" ;
55import { createAdapter } from "@socket.io/cluster-adapter" ;
66import { Server } from "socket.io" ;
7+ import { sleep } from "../util.ts" ;
78
89const WORKERS_COUNT = 3 ;
910const EXPECTED_PEERS_COUNT = 3 * WORKERS_COUNT - 1 ;
@@ -39,14 +40,26 @@ if (cluster.isPrimary) {
3940 cb ( process . pid ) ;
4041 } ) ;
4142
42- setTimeout ( ( ) => {
43+ function isInitComplete ( ) {
44+ return io . of ( "/" ) . adapter . nodesMap . size === EXPECTED_PEERS_COUNT ;
45+ }
46+
47+ async function runTest ( ) {
48+ io . of ( "/" ) . adapter . init ( ) ;
49+
50+ while ( ! isInitComplete ( ) ) {
51+ await sleep ( 20 ) ;
52+ }
53+
4354 io . serverSideEmit ( "test" , ( err , res ) => {
4455 assert . equal ( err , null ) ;
4556 assert . equal ( res . length , EXPECTED_PEERS_COUNT ) ;
4657
4758 setTimeout ( ( ) => {
48- process . exit ( 0 ) ;
59+ process . exit ( 0 ) ; // exit after having responded to other nodes
4960 } , GRACE_PERIOD_IN_MS ) ;
5061 } ) ;
51- } , GRACE_PERIOD_IN_MS ) ;
62+ }
63+
64+ runTest ( ) ;
5265}
You can’t perform that action at this time.
0 commit comments