aboutsummaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorSam Guymer <sam@guymer.me>2018-05-17 20:11:22 +1000
committerSam Guymer <sam@guymer.me>2018-05-19 00:37:52 +1000
commit92e10991df0d168d1972d4618fcc7e02e2e0a0fa (patch)
tree14e0d112fd47856a8c87ad1782d51a928b01bbf6 /project
parent588395d018c258eb74f60ad95bad706698bdf915 (diff)
downloadsttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.gz
sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.bz2
sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.zip
Move backend tests into their projects
Instead of having a single project which tests all backends, each backend now implements a http test trait along with a streaming test trait if it supports streaming. The test http server has been moved into its own project and is started automatically before running a backends test. This allows each backend to be tested without the possibility of dependency eviction from another backend or the test http server. It also has the side effect of parallelizing the tests providing a speed up when run with multiple cores.
Diffstat (limited to 'project')
-rw-r--r--project/PollingUtils.scala45
-rw-r--r--project/plugins.sbt7
2 files changed, 50 insertions, 2 deletions
diff --git a/project/PollingUtils.scala b/project/PollingUtils.scala
new file mode 100644
index 0000000..34b92ac
--- /dev/null
+++ b/project/PollingUtils.scala
@@ -0,0 +1,45 @@
+import java.io.FileNotFoundException
+import java.net.{ConnectException, URL}
+
+import scala.concurrent.TimeoutException
+import scala.concurrent.duration._
+
+object PollingUtils {
+
+ def waitUntilServerAvailable(url: URL): Unit = {
+ val connected = poll(5.seconds, 250.milliseconds)({
+ urlConnectionAvailable(url)
+ })
+ if (!connected) {
+ throw new TimeoutException(s"Failed to connect to $url")
+ }
+ }
+
+ def poll(timeout: FiniteDuration, interval: FiniteDuration)(poll: => Boolean): Boolean = {
+ val start = System.nanoTime()
+
+ def go(): Boolean = {
+ if (poll) {
+ true
+ } else if ((System.nanoTime() - start) > timeout.toNanos) {
+ false
+ } else {
+ Thread.sleep(interval.toMillis)
+ go()
+ }
+ }
+ go()
+ }
+
+ def urlConnectionAvailable(url: URL): Boolean = {
+ try {
+ url.openConnection()
+ .getInputStream
+ .close()
+ true
+ } catch {
+ case _: ConnectException => false
+ case _: FileNotFoundException => true // on 404
+ }
+ }
+}
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 1d83f24..b334460 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -1,4 +1,5 @@
-addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15")
+// using '-coursier' because of https://github.com/lucidsoftware/neo-sbt-scalafmt/issues/64
+addSbtPlugin("com.lucidchart" % "sbt-scalafmt-coursier" % "1.15")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
@@ -6,4 +7,6 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7")
-addSbtPlugin("com.updateimpact" % "updateimpact-sbt-plugin" % "2.1.3") \ No newline at end of file
+addSbtPlugin("com.updateimpact" % "updateimpact-sbt-plugin" % "2.1.3")
+
+addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")