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.
This commit is contained in:
Ludovic Courtès 2018-11-07 15:10:09 +01:00
parent 2c712d35df
commit 9a7e567bf2
1 changed files with 13 additions and 4 deletions

View File

@ -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)))