From da44202e48b2647ff0dbf203407fd4bcf9359f84 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Sun, 31 May 2020 17:54:25 +0200 Subject: [PATCH 1/6] add AsyncConditionsDocSpec --- docs/utilities.adoc | 29 +++++++++++ .../concurrent/AsyncConditionsDocSpec.groovy | 50 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy diff --git a/docs/utilities.adoc b/docs/utilities.adoc index aa2eae071a..8773d6eaab 100644 --- a/docs/utilities.adoc +++ b/docs/utilities.adoc @@ -37,3 +37,32 @@ include::{sourcedir}/utilities/MutableClockDocSpec.groovy[tag=age-filter-spec] There are many more ways to modify `MutableClock` just have a look at the JavaDocs, or the test code `spock.util.time.MutableClockSpec`. +[[async-conditions]] +== Evaluating conditions asynchronously with `AsyncConditions` + +The utility class `AsyncConditions` can be helpful when working with asynchronous assertions. These are assertions made +from a different thread than the one running the test, for example when working with callback functions. +The individual assertions are collected, and in the asserting block, e.g. `then`, the `await` method is called to +verify the individual results. If any of the results is not available when `await` is called, it will also fail. +The amount of seconds to wait for can be specified as a parameter, see the example below. The default is `1.0` seconds. +Additionally, the number of expected evaluations must be provided initially, the default value is `1`. + +=== Example + +.Test +[source,groovy,indent=0] +---- +include::{sourcedir}/utilities/concurrent/AsyncConditionsDocSpec.groovy[tag=async-conditions-spec] +---- +<1> create a default `AsyncConditions` object (expecting a single evaluation) +<2> A new thread is created, and code is passed to be run from it. This could also happen implicitly, when working with +a method expecting a callback parameter. +<3> pass any code that wants to do assertions to the `evaluate` method +<4> finally, call the `await` method + +<5> create an `AsyncConditions` object (expecting three evaluations) +<6> call `evaluate` multiple times +<7> call `await` in the end, specifying 2.5 seconds as the timeout + +For more information have a look at the test code `spock.util.concurrent.AsyncConditionsSpec`. + diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy new file mode 100644 index 0000000000..4b91cc23f5 --- /dev/null +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy @@ -0,0 +1,50 @@ +package org.spockframework.docs.utilities.concurrent + +import spock.lang.Specification +import spock.util.concurrent.AsyncConditions + +import java.util.concurrent.TimeUnit + +class AsyncConditionsDocSpec extends Specification { + +// tag::async-conditions-spec[] + def "example for single passing evaluation"() { + def conditions = new AsyncConditions() // <1> + + when: + Thread.start { // <2> + conditions.evaluate { //<3> + assert true + } + } + + then: + conditions.await() // <4> + } + + def "example for multiple passing evaluations"() { + def conditions = new AsyncConditions(3) // <5> + + when: + Thread.start { + conditions.evaluate { // <6> + assert true + assert true + } + conditions.evaluate { // <6> + assert true + } + } + + and: + Thread.start { + conditions.evaluate { // <6> + assert true + } + } + + then: + conditions.await(2.5) // <7> + } +} +// end::async-conditions-spec[] From dd85cff60e6e4aed006a728c013fcdc71f3cdfc4 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Sun, 31 May 2020 18:02:37 +0200 Subject: [PATCH 2/6] fix grammar --- .../docs/utilities/concurrent/AsyncConditionsDocSpec.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy index 4b91cc23f5..213e7d528b 100644 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit class AsyncConditionsDocSpec extends Specification { // tag::async-conditions-spec[] - def "example for single passing evaluation"() { + def "example of single passing evaluation"() { def conditions = new AsyncConditions() // <1> when: @@ -22,7 +22,7 @@ class AsyncConditionsDocSpec extends Specification { conditions.await() // <4> } - def "example for multiple passing evaluations"() { + def "example of multiple passing evaluations"() { def conditions = new AsyncConditions(3) // <5> when: From f495e9dd869441060e2f7e68072e7bd6626ee265 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Mon, 1 Jun 2020 16:57:34 +0200 Subject: [PATCH 3/6] add more docs, clean up --- docs/utilities.adoc | 54 +++++++++++++++++- .../concurrent/AsyncConditionsDocSpec.groovy | 24 ++++---- .../BlockingVariablesDocSpec.groovy | 48 ++++++++++++++++ .../PollingConditionsDocSpec.groovy | 56 +++++++++++++++++++ 4 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy create mode 100755 spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy diff --git a/docs/utilities.adoc b/docs/utilities.adoc index 8773d6eaab..818d6010fb 100644 --- a/docs/utilities.adoc +++ b/docs/utilities.adoc @@ -44,8 +44,8 @@ The utility class `AsyncConditions` can be helpful when working with asynchronou from a different thread than the one running the test, for example when working with callback functions. The individual assertions are collected, and in the asserting block, e.g. `then`, the `await` method is called to verify the individual results. If any of the results is not available when `await` is called, it will also fail. -The amount of seconds to wait for can be specified as a parameter, see the example below. The default is `1.0` seconds. -Additionally, the number of expected evaluations must be provided initially, the default value is `1`. +The maximum amount of seconds to wait for can be specified as a parameter, see the example below. The default is `1.0` +seconds. Additionally, the number of expected evaluations must be provided initially, the default value is `1`. === Example @@ -66,3 +66,53 @@ a method expecting a callback parameter. For more information have a look at the test code `spock.util.concurrent.AsyncConditionsSpec`. +[[polling-conditions]] +== Polling until conditions are fulfilled with `PollingConditions` + +If you need more fine grained control over asynchronous evaluation, the `PollingConditions` utility can be used in a +similar way to `AsyncConditions`. `PollingConditions` allows to configure the timeout, delay and a delay increasing factor +for the check. A single block of code is passed to the `eventually` method, which will evaluate this code, according to +given time parameters, and either pass or throw one of the appropriate Spock exceptions. +The `within` method can be used to override the timeout for a single invocation. +There are some caveats when using this class with the `def` keyword, see the test code `spock.util.concurrent.PollingConditionsSpec`. + +=== Example + +.Test +[source,groovy,indent=0] +---- +include::{sourcedir}/utilities/concurrent/PollingConditionsDocSpec.groovy[tag=polling-conditions-spec] +---- +<1> create a `PollingConditions` object, avoid the `def` keyword (see comment above) +<2> values are set to variables in an asynchronous way +<3> block of code containing assertions, passed in a `when` step +<4> verify the result by checking for exceptions +<5> only the last failed evaluation will be reported + +[[blocking-variables]] +== Evaluating asynchronous variables with `BlockingVariable` and `BlockingVariables` + +The two utility classes `BlockingVariable` and `BlockingVariables` are there to help with collecting variables that are +written asynchronously, e.g. from another thread. Reading the variable(s) will block the current thread until a value is +available and returned. +For a single variable, a type parameter can be provided, see the example below. +The maximum amount of seconds to wait for can be specified as a parameter, the default is `1.0` seconds. + +=== Example + +.Test +[source,groovy,indent=0] +---- +include::{sourcedir}/utilities/concurrent/BlockingVariablesDocSpec.groovy[tag=blocking-variables-spec] +---- +<1> create a `BlockingVariable` object, providing an optional type parameter +<2> A new thread is created, and immediately put to sleep for some time. Afterwards it will set the value. +<3> The value is accessed via the `get` method. This happens immediately, as the main thread is never interrupted. The +method will block until the value is available. + +<4> create a `BlockingVariables` object for multiple variables, providing an optional timeout +<5> set values for `foo`, `bar` and `baz` at some point in the future +<6> compare the variables, blocking this thread until they are available + +For more information have a look at the test code `spock.util.concurrent.BlockingVariableSpec`. + diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy index 213e7d528b..700fbf7b18 100644 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy @@ -3,48 +3,46 @@ package org.spockframework.docs.utilities.concurrent import spock.lang.Specification import spock.util.concurrent.AsyncConditions -import java.util.concurrent.TimeUnit - class AsyncConditionsDocSpec extends Specification { -// tag::async-conditions-spec[] + // tag::async-conditions-spec[] def "example of single passing evaluation"() { - def conditions = new AsyncConditions() // <1> + def conditions = new AsyncConditions() // <1> when: - Thread.start { // <2> - conditions.evaluate { //<3> + Thread.start { // <2> + conditions.evaluate { //<3> assert true } } then: - conditions.await() // <4> + conditions.await() // <4> } def "example of multiple passing evaluations"() { - def conditions = new AsyncConditions(3) // <5> + def conditions = new AsyncConditions(3) // <5> when: Thread.start { - conditions.evaluate { // <6> + conditions.evaluate { // <6> assert true assert true } - conditions.evaluate { // <6> + conditions.evaluate { // <6> assert true } } and: Thread.start { - conditions.evaluate { // <6> + conditions.evaluate { // <6> assert true } } then: - conditions.await(2.5) // <7> + conditions.await(2.5) // <7> } + // end::async-conditions-spec[] } -// end::async-conditions-spec[] diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy new file mode 100644 index 0000000000..c75d541358 --- /dev/null +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy @@ -0,0 +1,48 @@ +package org.spockframework.docs.utilities.concurrent + +import spock.lang.Specification +import spock.util.concurrent.BlockingVariable +import spock.util.concurrent.BlockingVariables + +class BlockingVariablesDocSpec extends Specification { + + // tag::blocking-variables-spec[] + def "single variable is read before it is written"() { + def list = new BlockingVariable>() // <1> + + when: + Thread.start { + Thread.sleep(250) // <2> + println "calling set" + list.set([1, 2, 3]) + } + + then: + println "calling get, blocking" + list.get() == [1, 2, 3] // <3> + } + + def "example of multiple variables"() { + def vars = new BlockingVariables(2.0) // <4> + + when: + Thread.start { + Thread.sleep(500) // <5> + println "setting bar and baz" + vars.bar = 2 + vars.baz = 3 + } + Thread.start { + Thread.sleep(250) // <5> + println "setting foo" + vars.foo = 1 + } + + then: + println "before comparison, blocking" + vars.foo == 1 // <6> + vars.bar == 2 + vars.baz == 3 + } + // end::blocking-variables-spec[] +} diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy new file mode 100755 index 0000000000..a922f9173b --- /dev/null +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy @@ -0,0 +1,56 @@ +package org.spockframework.docs.utilities.concurrent + +import org.spockframework.runtime.ConditionNotSatisfiedError +import org.spockframework.runtime.SpockTimeoutError +import spock.lang.Specification +import spock.util.concurrent.PollingConditions + +class PollingConditionsDocSpec extends Specification { + // tag::polling-conditions-spec[] + PollingConditions conditions = new PollingConditions() // <1> + + volatile int num = 0 + volatile String str = null + + def "time controls and their default values"() { + expect: + with(conditions) { + timeout == 1 + initialDelay == 0 + delay == 0.1 + factor == 1 + } + } + + def "succeeds if all conditions are eventually satisfied"() { + num = 42 + Thread.start { + sleep(500) // <2> + str = "hello" + } + + when: + conditions.eventually { // <3> + num == 42 + str == "hello" + } + + then: + noExceptionThrown() // <4> + } + + def "fails if any condition isn't satisfied in time"() { + num = 42 + + when: + conditions.eventually { + num == 42 + str == "bye" + } + + then: + def error = thrown(SpockTimeoutError) + error.cause instanceof ConditionNotSatisfiedError // <5> + } + // end::polling-conditions-spec[] +} From 65b2caa51fbe6db2455a471089a727ccc1f71074 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Sat, 11 Jul 2020 22:01:59 +0200 Subject: [PATCH 4/6] improve explanations and examples --- docs/utilities.adoc | 53 +++++++++++-------- .../concurrent/AsyncConditionsDocSpec.groovy | 14 ++--- .../PollingConditionsDocSpec.groovy | 31 ++++++++--- 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/docs/utilities.adoc b/docs/utilities.adoc index 818d6010fb..d3d8f0ab3f 100644 --- a/docs/utilities.adoc +++ b/docs/utilities.adoc @@ -42,10 +42,15 @@ There are many more ways to modify `MutableClock` just have a look at the JavaDo The utility class `AsyncConditions` can be helpful when working with asynchronous assertions. These are assertions made from a different thread than the one running the test, for example when working with callback functions. -The individual assertions are collected, and in the asserting block, e.g. `then`, the `await` method is called to -verify the individual results. If any of the results is not available when `await` is called, it will also fail. -The maximum amount of seconds to wait for can be specified as a parameter, see the example below. The default is `1.0` -seconds. Additionally, the number of expected evaluations must be provided initially, the default value is `1`. +The individual assertions are collected using the `evaluate` method, and in the asserting block, e.g. `then`, the +`await` method is called to verify the results, blocking until a timeout expires, and failing if any of the evaluations +failed. +The timeout in seconds can be specified as a parameter, see the example below. The default is `1.0` seconds. +Additionally, the number of expected evaluations must be provided initially, the default value is `1`. + +NOTE: In order to use implicit assertions, a typed instance of this class must be declared. When declaring an untyped +instance (using the `def` keyword), it is required to explicitly `assert` all statements inside the block (see example +below). === Example @@ -57,24 +62,28 @@ include::{sourcedir}/utilities/concurrent/AsyncConditionsDocSpec.groovy[tag=asyn <1> create a default `AsyncConditions` object (expecting a single evaluation) <2> A new thread is created, and code is passed to be run from it. This could also happen implicitly, when working with a method expecting a callback parameter. -<3> pass any code that wants to do assertions to the `evaluate` method +<3> Pass any code that wants to do assertions to the `evaluate` method. Because we declared the instance of +`AsyncConditions` using the `def` keyword, we have to use `assert` explicitly. <4> finally, call the `await` method -<5> create an `AsyncConditions` object (expecting three evaluations) -<6> call `evaluate` multiple times +<5> Create an `AsyncConditions` object (expecting three evaluations). This time we are using a statically typed +instance. +<6> Call `evaluate` multiple times. Using a typed instance above allows using implicit assertions (no `assert` keyword). +keyword. <7> call `await` in the end, specifying 2.5 seconds as the timeout -For more information have a look at the test code `spock.util.concurrent.AsyncConditionsSpec`. - [[polling-conditions]] == Polling until conditions are fulfilled with `PollingConditions` -If you need more fine grained control over asynchronous evaluation, the `PollingConditions` utility can be used in a -similar way to `AsyncConditions`. `PollingConditions` allows to configure the timeout, delay and a delay increasing factor -for the check. A single block of code is passed to the `eventually` method, which will evaluate this code, according to -given time parameters, and either pass or throw one of the appropriate Spock exceptions. -The `within` method can be used to override the timeout for a single invocation. -There are some caveats when using this class with the `def` keyword, see the test code `spock.util.concurrent.PollingConditionsSpec`. +The `PollingConditions` utility can be used to (repeatedly) check on asynchronous conditions. The difference compared to +`AsyncConditions` is that the result is obtained passively, there is no `await` method. +`PollingConditions` allows to configure the timeout, delay and a delay increasing factor for the checks. Any number of +code blocks are passed to the `eventually` method, which will evaluate them, according to given time parameters, and +either pass or throw one of the appropriate Spock exceptions. +The `within` method can be used to override the timeout for a single invocation. See the second example below for a more +complicated use case. + +NOTE: The same restriction when using the `def` keyword exists here also, see the note on `AsyncConditions` === Example @@ -83,11 +92,12 @@ There are some caveats when using this class with the `def` keyword, see the tes ---- include::{sourcedir}/utilities/concurrent/PollingConditionsDocSpec.groovy[tag=polling-conditions-spec] ---- -<1> create a `PollingConditions` object, avoid the `def` keyword (see comment above) +<1> create a `PollingConditions` object <2> values are set to variables in an asynchronous way -<3> block of code containing assertions, passed in a `when` step +<3> block(s) of code containing assertions, passed in a `when` step <4> verify the result by checking for exceptions -<5> only the last failed evaluation will be reported +<5> Override the timeout for a single invocation. Using `expect` (or `then`) here forces immediate evaluation. +<6> only the first failed evaluation will be reported [[blocking-variables]] == Evaluating asynchronous variables with `BlockingVariable` and `BlockingVariables` @@ -96,6 +106,8 @@ The two utility classes `BlockingVariable` and `BlockingVariables` are there to written asynchronously, e.g. from another thread. Reading the variable(s) will block the current thread until a value is available and returned. For a single variable, a type parameter can be provided, see the example below. +An instance of `BlockingVariables` allows setting properties to it dynamically, and comparisons (i.e. assertions) can be +made for the individual properties, accessing them by their name. The maximum amount of seconds to wait for can be specified as a parameter, the default is `1.0` seconds. === Example @@ -112,7 +124,4 @@ method will block until the value is available. <4> create a `BlockingVariables` object for multiple variables, providing an optional timeout <5> set values for `foo`, `bar` and `baz` at some point in the future -<6> compare the variables, blocking this thread until they are available - -For more information have a look at the test code `spock.util.concurrent.BlockingVariableSpec`. - +<6> compare the individual properties, blocking this thread until they are available diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy index 700fbf7b18..cf50092444 100644 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/AsyncConditionsDocSpec.groovy @@ -6,7 +6,7 @@ import spock.util.concurrent.AsyncConditions class AsyncConditionsDocSpec extends Specification { // tag::async-conditions-spec[] - def "example of single passing evaluation"() { + def "example of single passing explicit evaluation"() { def conditions = new AsyncConditions() // <1> when: @@ -20,24 +20,24 @@ class AsyncConditionsDocSpec extends Specification { conditions.await() // <4> } - def "example of multiple passing evaluations"() { - def conditions = new AsyncConditions(3) // <5> + def "example of multiple passing implicit evaluations"() { + AsyncConditions conditions = new AsyncConditions(3) // <5> when: Thread.start { conditions.evaluate { // <6> - assert true - assert true + true + true } conditions.evaluate { // <6> - assert true + true } } and: Thread.start { conditions.evaluate { // <6> - assert true + true } } diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy index a922f9173b..67a4f64581 100755 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy @@ -23,34 +23,51 @@ class PollingConditionsDocSpec extends Specification { } def "succeeds if all conditions are eventually satisfied"() { - num = 42 + + when: Thread.start { + num = 42 sleep(500) // <2> str = "hello" } - when: + then: conditions.eventually { // <3> num == 42 + } + + and: + conditions.eventually { // <3> str == "hello" } - then: + and: noExceptionThrown() // <4> } def "fails if any condition isn't satisfied in time"() { - num = 42 - when: - conditions.eventually { + given: + Thread.start { + num = 42 + sleep(500) // milliseconds <2> + str = "hello" + } + + expect: + conditions.within(0.1) { // seconds <5> num == 42 + } + + when: + conditions.eventually { // <3> + num == 0 str == "bye" } then: def error = thrown(SpockTimeoutError) - error.cause instanceof ConditionNotSatisfiedError // <5> + error.cause.message.contains('num == 0') // <6> } // end::polling-conditions-spec[] } From ec67cd6d1fb11387c027f2f942c1dab05e8429a1 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Sat, 11 Jul 2020 22:05:53 +0200 Subject: [PATCH 5/6] add missing timeout hint --- docs/utilities.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities.adoc b/docs/utilities.adoc index d3d8f0ab3f..2627eeb24d 100644 --- a/docs/utilities.adoc +++ b/docs/utilities.adoc @@ -104,7 +104,7 @@ include::{sourcedir}/utilities/concurrent/PollingConditionsDocSpec.groovy[tag=po The two utility classes `BlockingVariable` and `BlockingVariables` are there to help with collecting variables that are written asynchronously, e.g. from another thread. Reading the variable(s) will block the current thread until a value is -available and returned. +available and returned or the timeout is reached. For a single variable, a type parameter can be provided, see the example below. An instance of `BlockingVariables` allows setting properties to it dynamically, and comparisons (i.e. assertions) can be made for the individual properties, accessing them by their name. From b3344cc557ec2f4ae681d0041fa11fdc50b466b4 Mon Sep 17 00:00:00 2001 From: Thomas Hirsch Date: Fri, 31 Jul 2020 17:45:15 +0200 Subject: [PATCH 6/6] decrease timeouts in doc specs --- .../utilities/concurrent/BlockingVariablesDocSpec.groovy | 6 +++--- .../utilities/concurrent/PollingConditionsDocSpec.groovy | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy index c75d541358..5be4bd6088 100644 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/BlockingVariablesDocSpec.groovy @@ -12,7 +12,7 @@ class BlockingVariablesDocSpec extends Specification { when: Thread.start { - Thread.sleep(250) // <2> + Thread.sleep(25) // <2> println "calling set" list.set([1, 2, 3]) } @@ -27,13 +27,13 @@ class BlockingVariablesDocSpec extends Specification { when: Thread.start { - Thread.sleep(500) // <5> + Thread.sleep(50) // <5> println "setting bar and baz" vars.bar = 2 vars.baz = 3 } Thread.start { - Thread.sleep(250) // <5> + Thread.sleep(25) // <5> println "setting foo" vars.foo = 1 } diff --git a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy index 67a4f64581..8d0e57ae21 100755 --- a/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/docs/utilities/concurrent/PollingConditionsDocSpec.groovy @@ -27,7 +27,7 @@ class PollingConditionsDocSpec extends Specification { when: Thread.start { num = 42 - sleep(500) // <2> + sleep(25) // <2> str = "hello" } @@ -50,12 +50,12 @@ class PollingConditionsDocSpec extends Specification { given: Thread.start { num = 42 - sleep(500) // milliseconds <2> + sleep(25) // milliseconds <2> str = "hello" } expect: - conditions.within(0.1) { // seconds <5> + conditions.within(0.05) { // seconds <5> num == 42 }