diff --git a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy index bc064504b17..85a6d9ca769 100644 --- a/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy +++ b/junit/mockwebserver/src/test/groovy/io/fabric8/mockwebserver/DefaultMockServerTest.groovy @@ -23,7 +23,6 @@ import io.vertx.core.http.WebSocketClient import io.vertx.ext.web.client.WebClient import okhttp3.Headers import okhttp3.mockwebserver.RecordedRequest -import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.AsyncConditions @@ -34,8 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger class DefaultMockServerTest extends Specification { - @Shared - static def vertx = Vertx.vertx() + Vertx vertx = Vertx.vertx() DefaultMockServer server @@ -44,6 +42,7 @@ class DefaultMockServerTest extends Specification { WebSocketClient wsClient def setup() { + vertx = Vertx.vertx() server = new DefaultMockServer() server.start() client = WebClient.create(vertx) @@ -54,13 +53,9 @@ class DefaultMockServerTest extends Specification { server.shutdown() client.close() wsClient.close() - } - - def cleanupSpec() { vertx.close() } - def "getPort, should return a valid port"() { when: def result = server.getPort() @@ -625,6 +620,7 @@ class DefaultMockServerTest extends Specification { server.expect().get().withPath("/api/v1/users/watch") .andUpgradeToWebSocket() .open() + .immediately().andEmit("READY") .expectHttpRequest("/api/v1/create").andEmit("CREATED").once() .expectSentWebSocketMessage("CREATED").andEmit("WS-CREATED").once() .done() @@ -633,19 +629,19 @@ class DefaultMockServerTest extends Specification { Queue messages = new ArrayBlockingQueue<>(2) and: "A WebSocket request" def wsReq = wsClient.webSocket().connect(server.port, server.getHostName(), "/api/v1/users/watch") - and: "A WebSocket listener" + and: "A WebSocket listener that sends an HTTP request after WS connection initiated and WS request after HTTP request" wsReq.andThen { ws -> ws.result().textMessageHandler { text -> - messages.add(text) + if (text == "READY") { + client.get(server.port, server.getHostName(), "/api/v1/create").send() + .andThen {_ ->{ + ws.result().writeTextMessage("CREATED") + }} + } else { + messages.add(text) + } } } - and: "HTTP request after WS connection initiated and WS request after HTTP request" - wsReq.andThen { ws -> - client.get(server.port, server.getHostName(), "/api/v1/create").send() - .compose {_ ->{ - ws.result().writeTextMessage("CREATED") - }} - } and: "An instance of AsyncConditions" def async = new AsyncConditions(1)