]> gitweb.factorcode.org Git - factor.git/blob - basis/retries/retries-tests.factor
factor: add newlines to .factor files
[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     <immediate> { 1 } retries
10 ] [ retries-failed? ] must-fail-with
11
12 { 2 } [
13     [ dup 2 = [ "not 2!" throw ] unless ]
14     <immediate> { 1 2 } 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     10 20 <random-wait> { 1 } retries
21 ] [ retries-failed? ] must-fail-with
22
23 { 2 } [
24     [ dup 2 = [ "not 2!" throw ] unless ]
25     10 20 <random-wait> { 1 2 } 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 100 <exponential-wait> { 1 } retries
32 ] [ retries-failed? ] must-fail-with
33
34 { 2 } [
35     [ dup 2 = [ "not 2!" throw ] unless ]
36     1.1 100 <exponential-wait> { 1 2 } retries
37 ] unit-test
38
39
40 ! try n times with no sleeps
41 [
42     [ 2 = [ "not 2!" throw ] unless ]
43     <immediate> 2 retries
44 ] [ retries-failed? ] must-fail-with
45
46 { } [
47     [ 2 = [ "not 2!" throw ] unless ]
48     <immediate> 3 retries
49 ] unit-test
50
51 ! try n times with a random sleep
52 [
53     [ 2 = [ "not 2!" throw ] unless ]
54     10 20 <random-wait> 2 retries
55 ] [ retries-failed? ] must-fail-with
56
57 { } [
58     [ 2 = [ "not 2!" throw ] unless ]
59     10 20 <random-wait> 3 retries
60 ] unit-test
61
62 ! try n times with an exponentially increasing sleep
63 [
64     [ 2 = [ "not 2!" throw ] unless ]
65     1.1 100 <exponential-wait> 2 retries
66 ] [ retries-failed? ] must-fail-with
67
68 { } [
69     [ 2 = [ "not 2!" throw ] unless ]
70      1.1 100 <exponential-wait> 3 retries
71 ] unit-test
72