scala - How do I start a server before running a test suite in SBT? -
problem if test in test <<= (taska, taskb) { (a, b) => dofinally b
or test in test := (taskb dependson taska).value
, taska
forked
, sbt execution doesn't continue taskb
, get's stuck indefinitely. it's caused dofinally/dependson
, because makes single-threaded sequential execution. can't find other way order 2 tasks, make them run sequentially.
so far i've gotten far :
lazy val startserver = taskkey[unit]("start pingpong server before running scala-js tests") lazy val jvm = project.in(file("jvm")) fork in (test, runmain) := true startserver := { (runmain in test).totask(" com.example.pingpong").value } ) lazy val js = project.in(file("js")) test in test <<= (startserver in project("jvm", file("jvm")), test in(test, fastoptstage)) { (startserver, test) => startserver dofinally test } )
the sbt execution stops on task startserver
spawns thread, daemon one. tried fork in startserver := true
didn't help.
i tried dependson
, blocks :
test in test := { (test in(test, fastoptstage)).dependson(startserver in project("jvm", file("jvm"))).value }
if not start server in main class pingpong
, behaves expected. if this, works has random order of execution , don't know how enforce without dofinally
.
test in test := { (startserver in project("jvm", file("jvm"))).value (test in(test, fastoptstage)).value }
i think i'm gonna have try sbt-sequential or fork new process.
instead of dealing sbt can suggest more simple workaround. create class static method start server (it check server not yet started), , in each test explicitly start server. you'll need set "fork in test := true", run server in separate jvm , shutdown after tests finished.
i use approach starting embedded cassandra server integration tests
in case it's static method java, can same scala , companion object.
override def beforeall() { log.info(s"start embedded cassandra server") embeddedcassandraserverhelper.startembeddedcassandra("/timeseries.yaml") }
and
public static void startembeddedcassandra(string yamlfile, string tmpdir) throws ttransportexception, ioexception, configurationexception { if (cassandradaemon != null) { /* nothing cassandra started */ return; } // ... start new server }
Comments
Post a Comment