title: Jest/SuperTest how to correctly expect Socket Hangup across a set of promises?
body: <p>I have a test that says &quot;After approx X concurrent connections, I should see socket hangups since my service will stop answering someone hammering me.&quot;</p>
  <p>This works pretty well after a lot of painful trial and error, but because I am using
  <code> await Promise.all(myrequests)</code> the first time I see a hangup it throws a <code>socket hang up</code> exception.</p>
  <p>This works, but causes some error messages, since my routine for hanging up does some debug logging, and the test is over at this point.</p>
  <p>What's the best way to say: &quot;wait for all of these, even when they throw errors?&quot;</p>
  <p>My jest/supertest problem block looks something like:</p>
  <pre><code> //Send enough concurrent connections to trip the dropout
   for(var i = 0;MAX_CONCURRENT_CONNECTIONS+5;i++) 
      {
         requests.push(request(app).get('/'))   
      }
      //wait for all the connections to resolve    
      const t = async () =&gt; {          
         await Promise.all(requests);                    
      };
      //and make sure some drop off
      expect(t).toThrow(&quot;socket hang up&quot;); //this also doesn't match the error string right but that is because I'm not as experienced in this sort of thing as I'd like!
  
      //however after this, the test ends, and my back end logging causes problems since the test is over!
  </code></pre>
  <p>What's the best way to still wait for all promises in requests even when one throws on <code>await Promise.all(requests)</code>?</p>
  <p>I can do the following ugly bit of code, but I'm looking for the right way to write this :)</p>
  <pre><code>        let gotConnReset = false
          try
          {
             await Promise.all(requests);                                    
          }
          catch(err)
          {
              if(err.message == &quot;socket hang up&quot;)
              {
                  gotConnReset = true;
              }            
          }
          assert(gotConnReset === true);
          //wait for all the other requests so that Jest doesn't yell at us!
          await Promise.allSettled(requests); 
  
  </code></pre>