title: How to run a server (a process) for the duration of integration tests?
body: <p>My problem is that server process doesn't get shut down after the last integration test.</p>
  <p>In <code>integration.rs</code>, I have:</p>
  <pre class="lang-rust prettyprint-override"><code>lazy_static! {
      static ref SERVER: Arc&lt;Mutex&lt;duct::ReaderHandle&gt;&gt; = {
          println!(&quot;Starting server&quot;);
          Arc::new(Mutex::new(
              cmd!(&quot;cargo&quot;, &quot;run&quot;, &quot;--&quot;, &quot;13000&quot;)
                  .reader()
                  .expect(&quot;Valid server&quot;),
          ))
      };
  }
  
  async fn wait_for_server() {
      lazy_static::initialize(&amp;SERVER);
      // Code to wait
  }
  
  #[tokio::test]
  async fn integration_test_query_amount() -&gt; Result&lt;()&gt; {
      wait_for_server().await;
      let client = reqwest::Client::new();
      // Etc...
  }
  </code></pre>
  <p>The tests work, but the server stays running after the <code>cargo test</code> invocation finishes. Is there a nice recipe for starting up <em>and shutting down</em> a server like this?</p>