|
1 | 1 | package tubesocks
|
2 | 2 |
|
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._ |
4 | 8 |
|
5 | 9 | object TubesocksSpec extends Specification
|
6 | 10 | with unfiltered.specs2.netty.Served {
|
7 | 11 |
|
8 |
| - import unfiltered.netty.websockets.Planify |
9 |
| - import unfiltered.netty.websockets.{ Message, Text } |
10 |
| - |
11 | 12 | def setup =
|
12 | 13 | _.handler(Planify({
|
13 | 14 | case _ => {
|
14 |
| - case Message(s, Text(msg)) => s.send(msg) |
| 15 | + case UFMessage(s, Text(msg)) => s.send(msg) |
15 | 16 | }
|
16 | 17 | }))
|
17 | 18 |
|
18 | 19 | "Socks" should {
|
19 | 20 | "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]() |
23 | 22 | Sock.uri(host.to_uri.toString.replace("http", "ws")) {
|
24 | 23 | case tubesocks.Open(s) =>
|
25 | 24 | s.send("i'm open")
|
26 | 25 | case tubesocks.Message(t, _) =>
|
27 |
| - m += ("rec" -> t) |
28 |
| - l.countDown |
| 26 | + if (!promise.isCompleted) { |
| 27 | + promise.success(t) |
| 28 | + } |
29 | 29 | }
|
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 | + ) |
32 | 33 | }
|
33 | 34 | }
|
34 | 35 | }
|
0 commit comments