  @Test
  public void aRunningStreamShouldPreventActorSystemFromShuttingDown() throws Exception {

    AkkaEngine engine = AkkaEngineProvider.provider();
    ActorSystem system = ((ActorMaterializer) engine.materializer).system();

    Flow.Publisher<Done> publisher =
        Source.tick(
            Duration.create(100, TimeUnit.MILLISECONDS),
            Duration.create(100, TimeUnit.MILLISECONDS),
            Done.getInstance()
        )
            .runWith(JavaFlowSupport.Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), engine.materializer);

    AtomicReference<RuntimeException> error = new AtomicReference<>();
    ReactiveStreams.fromPublisher(publisher).forEach(d -> {
      if (error.get() != null) {
        throw error.get();
      }
    }).build(engine);
    publisher = null;

    engine = null;
    Thread.sleep(300);

    // And gc
    System.gc();
    // Wait for it to possibly complete
    Thread.sleep(1000);
    // Now ensure it doesn't complete
    assertFalse(system.whenTerminated().isCompleted());

    // Stop the stream
    error.set(new RuntimeException());
    // Wait for the stream to shutdown
    Thread.sleep(1000);
    // gc again
    System.gc();
    // Now ensure it does complete
    FutureConverters.toJava(system.whenTerminated()).toCompletableFuture().get(10, TimeUnit.SECONDS);
  }