-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
polling.feature
45 lines (41 loc) · 1.41 KB
/
polling.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Feature: demo of how to poll until a certain condition is met
Background:
# first we re-set the counter to avoid collisions with other tests
Given url demoBaseUrl
And path 'greeting', 'reset'
When method get
Then status 200
And match response == { counter: 0 }
# you may prefer to read the javascript from a file instead of having it in-line
* def waitUntil =
"""
function(x) {
while (true) {
var result = karate.call('get.feature');
var greeting = result.response;
karate.log('poll response', greeting); //<
if (greeting.id >= x) {
karate.log('condition satisfied, exiting');
return;
}
karate.log('sleeping');
// uncomment / modify the sleep time as per your wish
// java.lang.Thread.sleep(1000);
}
}
"""
Scenario: get greeting and keep polling until id is n + 5
using javascript, and a second feature
* def result = call read('get.feature')
* def current = result.response
* print 'current: ' + current
* def target = current.id + 5
* call waitUntil target
Scenario: using the karate retry syntax
# if not configured, 'retry' defaults to
# { count: 3, interval: 3000 } (milliseconds)
* configure retry = { count: 5, interval: 0 }
Given url demoBaseUrl
And path 'greeting'
And retry until responseStatus == 200 && response.id > 3
When method get