1 ! Copyright (C) 2021 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel namespaces retries tools.test ;
6 ! try every value in a sequence with no sleeps
8 [ dup 2 = [ "not 2!" throw ] unless ]
9 <immediate> { 1 } retries
10 ] [ retries-failed? ] must-fail-with
13 [ dup 2 = [ "not 2!" throw ] unless ]
14 <immediate> { 1 2 } retries
17 ! try every value in a sequence with a random sleep
19 [ dup 2 = [ "not 2!" throw ] unless ]
20 10 20 <random-wait> { 1 } retries
21 ] [ retries-failed? ] must-fail-with
24 [ dup 2 = [ "not 2!" throw ] unless ]
25 10 20 <random-wait> { 1 2 } retries
28 ! try every value in a sequence with an exponentially increasing sleep
30 [ dup 2 = [ "not 2!" throw ] unless ]
31 1.1 100 <exponential-wait> { 1 } retries
32 ] [ retries-failed? ] must-fail-with
35 [ dup 2 = [ "not 2!" throw ] unless ]
36 1.1 100 <exponential-wait> { 1 2 } retries
40 ! try n times with no sleeps
42 [ 2 = [ "not 2!" throw ] unless ]
44 ] [ retries-failed? ] must-fail-with
47 [ 2 = [ "not 2!" throw ] unless ]
51 ! try n times with a random sleep
53 [ 2 = [ "not 2!" throw ] unless ]
54 10 20 <random-wait> 2 retries
55 ] [ retries-failed? ] must-fail-with
58 [ 2 = [ "not 2!" throw ] unless ]
59 10 20 <random-wait> 3 retries
62 ! try n times with an exponentially increasing sleep
64 [ 2 = [ "not 2!" throw ] unless ]
65 1.1 100 <exponential-wait> 2 retries
66 ] [ retries-failed? ] must-fail-with
69 [ 2 = [ "not 2!" throw ] unless ]
70 1.1 100 <exponential-wait> 3 retries