aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-11-07 15:10:09 +0100
committerLudovic Courtès <ludo@gnu.org>2018-11-07 15:28:05 +0100
commit9a7e567bf2389de35d470ef8f8d6188b89442081 (patch)
tree487cefa39de9bd24ec48291f57335ea4fc63b3ad
parent2c712d35df5d1514e28b479f960a53b89ce59424 (diff)
downloadcuirass-9a7e567bf2389de35d470ef8f8d6188b89442081.tar
cuirass-9a7e567bf2389de35d470ef8f8d6188b89442081.tar.gz
examples: random: Fail evaluation once in a while.
* examples/random-jobs.scm (make-random-jobs): Fail once in a while. (%seed, %state): New variables. (random-derivation): Use %SEED.
-rw-r--r--examples/random-jobs.scm17
1 files changed, 13 insertions, 4 deletions
diff --git a/examples/random-jobs.scm b/examples/random-jobs.scm
index d623b25..e820c0a 100644
--- a/examples/random-jobs.scm
+++ b/examples/random-jobs.scm
@@ -30,20 +30,26 @@
(#:description "dummy job")
(#:long-description "really dummy job"))))
+(define %seed
+ (logxor (cdr (gettimeofday))
+ (car (gettimeofday))
+ (cdr (gettimeofday))))
+
+(define %state
+ (seed->random-state %seed))
+
(define* (random-derivation store #:optional (suffix ""))
(let ((nonce (random 1e6)))
(run-with-store store
(gexp->derivation (string-append "random" suffix)
- #~(let* ((seed (logxor #$(cdr (gettimeofday))
- (car (gettimeofday))
- (cdr (gettimeofday))))
- (state (seed->random-state seed)))
+ #~(let ((state (seed->random-state #$%seed)))
(sleep (pk 'sleeping (random 10 state)))
(when (zero? (random 4 state))
(error "we're faillliiiiing!"))
#$nonce
(mkdir #$output))))))
+
(define (make-random-jobs store arguments)
(let ((checkout (assq-ref arguments 'cuirass)))
(format (current-error-port)
@@ -51,6 +57,9 @@
(assq-ref checkout 'file-name)
(assq-ref checkout 'revision)))
+ (when (zero? (random 7 %state))
+ (error "Evaluation is failing!"))
+
(unfold (cut > <> 10)
(lambda (i)
(let ((suffix (number->string i)))