Spock Web Console

subscribe to the feed Subscribe
PollingConditionsTest (via #spockwebconsole)
tweet this script Tweet

PollingConditionsTest

Published 2 months ago by Myself with tags spock polling async await pollingconditions
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

interface Foo {
   int bar();
}

class PollingConditionsSpec extends Specification {

    Foo m = Mock()

    def "polling conditions test"() {
        given:
            PollingConditions conditions = new PollingConditions(timeout: 10)
        when:
            Thread.start {
                sleep(1000)
                m.bar()
            }
            // uncomment to 'fix'
            // Thread.sleep(2000)
        then:
            conditions.eventually {
                1 * m.bar()
            }
    }
}