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 { 1 } <immediate> retries
10 ] [ retries-failed? ] must-fail-with
13 [ dup 2 = [ "not 2!" throw ] unless ]
14 { 1 2 } <immediate> retries
17 ! try every value in a sequence with a random sleep
19 [ dup 2 = [ "not 2!" throw ] unless ]
20 { 1 } 10 20 <random-wait> retries
21 ] [ retries-failed? ] must-fail-with
24 [ dup 2 = [ "not 2!" throw ] unless ]
25 { 1 2 } 10 20 <random-wait> retries
28 ! try every value in a sequence with an exponentially increasing sleep
30 [ dup 2 = [ "not 2!" throw ] unless ]
31 { 1 } 1.1 100 <exponential-wait> retries
32 ] [ retries-failed? ] must-fail-with
35 [ dup 2 = [ "not 2!" throw ] unless ]
36 { 1 2 } 1.1 100 <exponential-wait> 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 2 10 20 <random-wait> retries
55 ] [ retries-failed? ] must-fail-with
58 [ 2 = [ "not 2!" throw ] unless ]
59 3 10 20 <random-wait> retries
62 ! try n times with an exponentially increasing sleep
64 [ 2 = [ "not 2!" throw ] unless ]
65 2 1.1 100 <exponential-wait> retries
66 ] [ retries-failed? ] must-fail-with
69 [ 2 = [ "not 2!" throw ] unless ]
70 3 1.1 100 <exponential-wait> retries