Spock Web Console

subscribe to the feed Subscribe
Another polling test (via #spockwebconsole)
tweet this script Tweet

Another polling test

Published 8 months ago by Myself
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()
                println "Called bar()"
            }
            // uncomment to 'fix'
            // Thread.sleep(2000)
        then:
            conditions.eventually {
                assert 1 * m.bar()
            }
    }
}