mirror of https://github.com/sbt/sbt.git
Merge pull request #1 from eed3si9n/wip/fix-parsing-id
Add test case for number id in JSON-RPC
This commit is contained in:
commit
9d01bdff68
|
|
@ -9,6 +9,7 @@ package sbt
|
|||
|
||||
import org.scalatest._
|
||||
import scala.concurrent._
|
||||
import scala.annotation.tailrec
|
||||
import java.io.{ InputStream, OutputStream }
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.{ ThreadFactory, ThreadPoolExecutor }
|
||||
|
|
@ -23,15 +24,22 @@ class ServerSpec extends AsyncFlatSpec with Matchers {
|
|||
"""{ "jsonrpc": "2.0", "id": 3, "method": "sbt/setting", "params": { "setting": "root/name" } }""",
|
||||
out)
|
||||
Thread.sleep(100)
|
||||
val l2 = contentLength(in)
|
||||
println(l2)
|
||||
readLine(in)
|
||||
readLine(in)
|
||||
val x2 = readContentLength(in, l2)
|
||||
println(x2)
|
||||
assert(1 == 1)
|
||||
assert(waitFor(in, 10) { s =>
|
||||
s contains """"id":3"""
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@tailrec
|
||||
private[this] def waitFor(in: InputStream, num: Int)(f: String => Boolean): Boolean = {
|
||||
if (num < 0) false
|
||||
else
|
||||
readFrame(in) match {
|
||||
case Some(x) if f(x) => true
|
||||
case _ =>
|
||||
waitFor(in, num - 1)(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ServerSpec {
|
||||
|
|
@ -90,6 +98,13 @@ object ServerSpec {
|
|||
writeLine(message, out)
|
||||
}
|
||||
|
||||
def readFrame(in: InputStream): Option[String] = {
|
||||
val l = contentLength(in)
|
||||
readLine(in)
|
||||
readLine(in)
|
||||
readContentLength(in, l)
|
||||
}
|
||||
|
||||
def contentLength(in: InputStream): Int = {
|
||||
readLine(in) map { line =>
|
||||
line.drop(16).toInt
|
||||
|
|
|
|||
Loading…
Reference in New Issue