From 635d029357d1beba42f794151b9655598aae0cd9 Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:00:40 -0600 Subject: [PATCH] Make tests more reliable --- src/main/java/mdnet/cache/CachingInputStream.java | 13 +++++++++++++ src/test/kotlin/mdnet/server/ImageServerTest.kt | 3 --- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/mdnet/cache/CachingInputStream.java b/src/main/java/mdnet/cache/CachingInputStream.java index cec35a4..b5f06f6 100644 --- a/src/main/java/mdnet/cache/CachingInputStream.java +++ b/src/main/java/mdnet/cache/CachingInputStream.java @@ -40,6 +40,19 @@ public class CachingInputStream extends ProxyInputStream { @Override public void close() throws IOException { + if (read() == EOF) { + try { + in.close(); + } catch (IOException ignored) { + } + try { + cache.close(); + } catch (IOException ignored) { + } + onClose.run(); + + return; + } executor.submit(() -> { try { IOUtils.copy(in, cache); diff --git a/src/test/kotlin/mdnet/server/ImageServerTest.kt b/src/test/kotlin/mdnet/server/ImageServerTest.kt index 4e91a54..4b27814 100644 --- a/src/test/kotlin/mdnet/server/ImageServerTest.kt +++ b/src/test/kotlin/mdnet/server/ImageServerTest.kt @@ -150,9 +150,6 @@ class ImageServerTest : FreeSpec() { response.shouldHaveHeader("Content-Length", mockData.size.toString()) IOUtils.toByteArray(response.body.stream).shouldBe(mockData) response.close() - - // wait for the executor to commit - delay(100) } } }