title: How to stop Apollo-Server
body: <p>I am starting apollo-server with unittests and would like to gracefully stop the server, but in unit tests I get <code>Error: listen EADDRINUSE: address already in use :::4000 (and Mocha's done() called multiple times)</code></p>
  <p>Here the start and stop functions:</p>
  <pre><code>let apollo_server = null;
  
  exports.start = function(options, callback) {
    options.schema = schema
    options.formatError = (error) =&gt; {
      console.log('Fail to start graphql server', error);
      return error;
    }
    apollo_server = new ApolloServer(options);
    apollo_server.listen().then(({ url, subscriptionsUrl }) =&gt; {
      console.log('Grapql server started.', url, subscriptionsUrl);
    });
    callback();
  }
  
  exports.stop = function(callback) {
    apollo_server.stop().then(()=&gt;{
       console.log(&quot;server stopped&quot;)l
       callback();
       })
  }
  </code></pre>
  <p>Testing is done with Apollo-link, apollo-links-ws and subscriptions-transport-ws. It starts with following config to access graphql server&gt;</p>
  <pre><code>const serverConfig = { serverUrl: 'http://localhost:4000/', subscriptionUrl: 'ws://localhost:4000/graphql' };
  </code></pre>
  <p>The test looks like following:</p>
  <pre><code>describe('Start query', function() {
  
    before('Start the graphql server', function(callback) {
      const options = { playground: false };
      graphql_server.start(options, callback);
    });
  
  
    before('Create owner', function(callback) {
      datasource.new_owner({ name: &quot;test1&quot; })
      callback()
    });
  
    it('Should return created entry of a query', (callback) =&gt; {
      owner_query.variables = { id: '4711' }
      execute(link, owner_query).subscribe({
        next: ({ data }) =&gt; {
          expect(data.owners.length).to.be.equal(1)
          callback()
        },
        error: error =&gt; { expect(error).to.be.null },
        complete: () =&gt; {},
      });
    })
  
    after('Stop server', function(callback) {
      graphql_server.stop((data) =&gt; {
        console.log(&quot;stop1&quot;, data)
        callback()
      })
    })
  })
  </code></pre>
  <p>This is the second test. The first is similar for a mutation and is does not throw an error. The second test case ends with error on listen EADDRINUSE of port 4000.</p>
  <p>What do I miss?</p>