File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class GraphqlWsTests: XCTestCase {
1010    var  serverMessenger :  TestMessenger ! 
1111    var  server :  Server < TokenInitPayload ,  AsyncThrowingStream < GraphQLResult ,  Error > > ! 
1212    var  context :  TestContext ! 
13+     var  subscribeReady :  Bool !  =  false 
1314
1415    override func  setUp( )  { 
1516        // Point the client and server at each other
@@ -30,10 +31,12 @@ class GraphqlWsTests: XCTestCase {
3031                ) 
3132            } , 
3233            onSubscribe:  {  graphQLRequest in 
33-                 try await  api. subscribe ( 
34+                 let   subscription   =   try await  api. subscribe ( 
3435                    request:  graphQLRequest. query, 
3536                    context:  context
3637                ) . get ( ) 
38+                 self . subscribeReady =  true 
39+                 return  subscription
3740            } 
3841        ) 
3942        self . context =  context
@@ -168,8 +171,15 @@ class GraphqlWsTests: XCTestCase {
168171                    id:  id
169172                ) 
170173
171-                 // Short sleep to allow for server to register subscription
172-                 usleep ( 3000 ) 
174+                 // Wait until server has registered subscription
175+                 var  i  =  0 
176+                 while  !self . subscribeReady,  i <  50  { 
177+                     usleep ( 1000 ) 
178+                     i =  i +  1 
179+                 } 
180+                 if  i ==  50  { 
181+                     XCTFail ( " Subscription timeout: Took longer than 50ms to set up " ) 
182+                 } 
173183
174184                self . context. publisher. emit ( event:  " hello  \( dataIndex) " ) 
175185            } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments