Skip to content

Commit 3b43bb2

Browse files
committed
we are on 2.10 now so we can use promises
1 parent e1a73e5 commit 3b43bb2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/test/scala/spec.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
package tubesocks
22

3-
import org.specs2.mutable._
3+
import unfiltered.netty.websockets.Planify
4+
import unfiltered.netty.websockets.{ Message => UFMessage, Text }
5+
import org.specs2.mutable.Specification
6+
import scala.concurrent.Promise
7+
import scala.concurrent.duration._
48

59
object TubesocksSpec extends Specification
610
with unfiltered.specs2.netty.Served {
711

8-
import unfiltered.netty.websockets.Planify
9-
import unfiltered.netty.websockets.{ Message, Text }
10-
1112
def setup =
1213
_.handler(Planify({
1314
case _ => {
14-
case Message(s, Text(msg)) => s.send(msg)
15+
case UFMessage(s, Text(msg)) => s.send(msg)
1516
}
1617
}))
1718

1819
"Socks" should {
1920
"receive messages" in {
20-
import java.util.concurrent.{ CountDownLatch, TimeUnit }
21-
var m = scala.collection.mutable.Map.empty[String, String]
22-
val l = new CountDownLatch(1)
21+
val promise = Promise[String]()
2322
Sock.uri(host.to_uri.toString.replace("http", "ws")) {
2423
case tubesocks.Open(s) =>
2524
s.send("i'm open")
2625
case tubesocks.Message(t, _) =>
27-
m += ("rec" -> t)
28-
l.countDown
26+
if (!promise.isCompleted) {
27+
promise.success(t)
28+
}
2929
}
30-
l.await(2, TimeUnit.MILLISECONDS)
31-
m must havePair(("rec", "i'm open"))
30+
promise.future must be_==("i'm open").await(
31+
retries = 5, Duration(2, MILLISECONDS)
32+
)
3233
}
3334
}
3435
}

0 commit comments

Comments
 (0)