From 7d187fe738e44283fd7e4e49ae0375206001b03b Mon Sep 17 00:00:00 2001 From: evolv34 Date: Sun, 16 Dec 2018 17:59:58 -0500 Subject: [PATCH] fix test cases issue #10 --- .../com/evolv/metrics/reporter/GraphiteReporterSpec.scala | 5 ++--- src/test/scala/com/evolv/metrics/utils/MockServer.scala | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/scala/com/evolv/metrics/reporter/GraphiteReporterSpec.scala b/src/test/scala/com/evolv/metrics/reporter/GraphiteReporterSpec.scala index aec7e0c..8e7c07b 100644 --- a/src/test/scala/com/evolv/metrics/reporter/GraphiteReporterSpec.scala +++ b/src/test/scala/com/evolv/metrics/reporter/GraphiteReporterSpec.scala @@ -10,10 +10,9 @@ import scala.concurrent.duration.Duration class GraphiteReporterSpec extends UnitSpec { val mockServerPort = 12003 - val mockServer = MockServer(mockServerPort) "GraphiteReporter.write" should "take the time from message and write the sink record to timeseries database" in { - val serverFuture = mockServer.init() + val serverFuture = MockServer(mockServerPort).init() val graphiteReporter = GraphiteReporter("localhost", mockServerPort.toString) val (metric, sinkRecord) = getSinkRecord(Some((System.currentTimeMillis / 1000).toString)) @@ -24,7 +23,7 @@ class GraphiteReporterSpec extends UnitSpec { } it should "take the current time and write the sink record to timeseries database" in { - val serverFuture = mockServer.init() + val serverFuture = MockServer(mockServerPort).init() val graphiteReporter = GraphiteReporter("localhost", mockServerPort.toString) val (metric, sinkRecord) = getSinkRecord(None) diff --git a/src/test/scala/com/evolv/metrics/utils/MockServer.scala b/src/test/scala/com/evolv/metrics/utils/MockServer.scala index 91ec29b..fc5b9ed 100644 --- a/src/test/scala/com/evolv/metrics/utils/MockServer.scala +++ b/src/test/scala/com/evolv/metrics/utils/MockServer.scala @@ -9,6 +9,7 @@ import scala.concurrent.Future class MockServer(port: Int) { + def init():Future[String] = Future { val server = new ServerSocket(port) val s = server.accept() @@ -17,10 +18,10 @@ class MockServer(port: Int) { val data = serverInputStream.readLine() serverInputStream.close() + s.close() server.close() data } - TimeUnit.SECONDS.sleep(5) } object MockServer {