Skip to content

Instantly share code, notes, and snippets.

@InfoSec812
Last active September 22, 2017 16:27
Show Gist options
  • Select an option

  • Save InfoSec812/f0083f8038da4d230a63137f7f8118e2 to your computer and use it in GitHub Desktop.

Select an option

Save InfoSec812/f0083f8038da4d230a63137f7f8118e2 to your computer and use it in GitHub Desktop.
Demonstration Of Spock AsyncConditions With Vert.x
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