Last active
September 22, 2017 16:27
-
-
Save InfoSec812/f0083f8038da4d230a63137f7f8118e2 to your computer and use it in GitHub Desktop.
Demonstration Of Spock AsyncConditions With Vert.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.vertx.core.Vertx | |
| import io.vertx.core.http.RequestOptions | |
| import spock.lang.Specification | |
| import spock.util.concurrent.AsyncConditions | |
| class AsyncExampleSpec extends Specification { | |
| def "Async request for google.com should return proper page content"() { | |
| given: "An async HTTP client" | |
| def client = Vertx.vertx().createHttpClient() | |
| and: "Some HTTP request options" | |
| def opts = new RequestOptions() | |
| opts.ssl = true | |
| opts.port = 443 | |
| opts.host = 'www.google.com' | |
| opts.URI = '/' | |
| and: "An instance of AsyncConditions" | |
| def async = new AsyncConditions(1) // Create the instance of AsyncConditions which will expect 1 async operation | |
| when: "The google.com web site is requested" | |
| client.getNow(opts, { res -> // This Closure is handling the async results from the HTTP request | |
| async.evaluate { // The async.evaluate closure resolves the AsyncCondition | |
| res.statusCode() == 200 | |
| } | |
| }) | |
| then: "Expect the result to be completed in the specified time" | |
| async.await(5.5) // If the AsyncCondition is not resolved in 5.5 seconds, the test fails. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment