]> gitweb.factorcode.org Git - factor.git/blob - basis/retries/retries-tests.factor
retries: Add a retry vocabulary that tries n times or each element of a sequence...
[factor.git] / basis / retries / retries-tests.factor
1 ! Copyright (C) 2021 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel namespaces retries tools.test ;
4 IN: retries.tests
5
6 ! try every value in a sequence with no sleeps
7 [
8     [ dup 2 = [ "not 2!" throw ] unless ]
9     { 1 } <immediate> retries
10 ] [ retries-failed? ] must-fail-with
11
12 { 2 } [
13     [ dup 2 = [ "not 2!" throw ] unless ]
14     { 1 2 } <immediate> retries
15 ] unit-test
16
17 ! try every value in a sequence with a random sleep
18 [
19     [ dup 2 = [ "not 2!" throw ] unless ]
20     { 1 } 10 20 <random-wait> retries
21 ] [ retries-failed? ] must-fail-with
22
23 { 2 } [
24     [ dup 2 = [ "not 2!" throw ] unless ]
25     { 1 2 } 10 20 <random-wait> retries
26 ] unit-test
27
28 ! try every value in a sequence with an exponentially increasing sleep
29 [
30     [ dup 2 = [ "not 2!" throw ] unless ]
31     { 1 } 1.1 100 <exponential-wait> retries
32 ] [ retries-failed? ] must-fail-with
33
34 { 2 } [
35     [ dup 2 = [ "not 2!" throw ] unless ]
36     { 1 2 } 1.1 100 <exponential-wait> retries
37 ] unit-test
38
39
40 ! try n times with no sleeps
41 [
42     [ 2 = [ "not 2!" throw ] unless ]
43     2 <immediate> retries
44 ] [ retries-failed? ] must-fail-with
45
46 { } [
47     [ 2 = [ "not 2!" throw ] unless ]
48     3 <immediate> retries
49 ] unit-test
50
51 ! try n times with a random sleep
52 [
53     [ 2 = [ "not 2!" throw ] unless ]
54     2 10 20 <random-wait> retries
55 ] [ retries-failed? ] must-fail-with
56
57 { } [
58     [ 2 = [ "not 2!" throw ] unless ]
59     3 10 20 <random-wait> retries
60 ] unit-test
61
62 ! try n times with an exponentially increasing sleep
63 [
64     [ 2 = [ "not 2!" throw ] unless ]
65     2 1.1 100 <exponential-wait> retries
66 ] [ retries-failed? ] must-fail-with
67
68 { } [
69     [ 2 = [ "not 2!" throw ] unless ]
70     3 1.1 100 <exponential-wait> retries
71 ] unit-test