Skip to content

Commit

Permalink
Issue spockframework#1054 | Added warning to PollingConditions docume…
Browse files Browse the repository at this point in the history
…ntation as wel… (spockframework#1055)

* Issue spockframework#1054 | Added warning to PollingConditions documentation as well as test that explains the issue

* Slightly rework pending feature with PollingConditions limitation
  • Loading branch information
macieg authored and szpak committed Nov 25, 2019
1 parent 59b8421 commit 9485401
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
* As in expect-blocks and then-blocks, variable declarations
* and void method invocations will not be considered conditions.
*
* <p>This annotation only takes effect if the closures are passed as literals,
* and the Groovy compiler can (at compilation time) determine the target
* type of the method invocation referencing the annotated method. If the annotated
* method is overloaded, the closure arguments of all overloads are considered code blocks.
* <p>This annotation only takes effect if:
* - the closures are passed as literals, and the Groovy compiler can (at compilation time) determine the target
* type of the method invocation referencing the annotated method,
* - the annotated method is called on object of type known at compilation time (no "def").
* If the annotated method is overloaded, the closure arguments of all overloads are considered code blocks.
*/
@Beta
@Target(ElementType.METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
* assert machine.efficiency >= 0.9
* }
* </pre>
*
* Warning! Avoiding assert keyword in the clojure is only possible if the conditions object type is known
* during compilation (no "def" on the left side):
* <pre>
* PollingConditions conditions = new PollingConditions(timeout: 10, initialDelay: 1.5, factor: 1.25)
* </pre>
*/
@Beta
public class PollingConditions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package spock.util.concurrent
import org.spockframework.runtime.ConditionNotSatisfiedError
import org.spockframework.runtime.SpockTimeoutError
import spock.lang.Issue
import spock.lang.PendingFeature
import spock.lang.Specification

class PollingConditionsSpec extends Specification {
PollingConditions conditions = new PollingConditions()
def defConditions = new PollingConditions()

volatile int num = 0
volatile String str = null
Expand Down Expand Up @@ -83,6 +85,32 @@ class PollingConditionsSpec extends Specification {
}
}

def "fails if condition is not met and assert keyword is used for def declared conditions object"() {
num = 50

when:
defConditions.eventually {
assert num == 42
}

then:
thrown(SpockTimeoutError)
}

@PendingFeature(reason = "Known limitation")
@Issue("https://github.com/spockframework/spock/issues/1054")
def "fails if condition is not met and assert keyword is not used for def declared conditions object"() {
num = 50

when:
defConditions.eventually {
num == 42
}

then:
thrown(SpockTimeoutError)
}

def "can override timeout per invocation"() {
Thread.start {
Thread.sleep(250)
Expand Down

0 comments on commit 9485401

Please sign in to comment.