| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (test-store-deadlock)
|
| 21 | #:use-module (guix tests)
|
| 22 | #:use-module (guix store)
|
| 23 | #:use-module (guix derivations)
|
| 24 | #:use-module (guix gexp)
|
| 25 | #:use-module (guix monads)
|
| 26 | #:use-module (gnu packages bootstrap)
|
| 27 | #:use-module (ice-9 threads)
|
| 28 | #:use-module (srfi srfi-1)
|
| 29 | #:use-module (srfi srfi-64))
|
| 30 |
|
| 31 | (define input-drvs
|
| 32 | (map (lambda (n)
|
| 33 | (computed-file (string-append "drv" (number->string n))
|
| 34 | #~(begin
|
| 35 | #$(random-text)
|
| 36 | (sleep 4)
|
| 37 | (mkdir #$output))
|
| 38 | #:guile %bootstrap-guile))
|
| 39 | (iota 15)))
|
| 40 |
|
| 41 | (define top-drv
|
| 42 | (computed-file "top-drv"
|
| 43 | #~(begin
|
| 44 | #$(random-text)
|
| 45 | (sleep 3)
|
| 46 | (pk 'deps: #$@input-drvs)
|
| 47 | (mkdir #$output))
|
| 48 | #:guile %bootstrap-guile))
|
| 49 |
|
| 50 | (%graft? #f)
|
| 51 |
|
| 52 |
|
| 53 | (test-begin "store-deadlock")
|
| 54 |
|
| 55 | (test-equal "no deadlock" |
| 56 | '(thread1 thread2 thread3)
|
| 57 |
|
| 58 | |
| 59 | |
| 60 | |
| 61 | (let* ((drvs (cons top-drv input-drvs))
|
| 62 | (builder (lambda (name lst)
|
| 63 | (call-with-new-thread
|
| 64 | (lambda ()
|
| 65 | (with-store store
|
| 66 | (set-build-options store
|
| 67 | #:verbosity 3
|
| 68 | #:max-build-jobs 1)
|
| 69 | (run-with-store store
|
| 70 | (mlet %store-monad ((lst (mapm %store-monad
|
| 71 | lower-object lst)))
|
| 72 | (mbegin %store-monad
|
| 73 | (built-derivations lst)
|
| 74 | (return name)))))))))
|
| 75 | (thread1 (builder 'thread1 drvs))
|
| 76 | (thread2 (begin
|
| 77 | (sleep 1)
|
| 78 | (builder 'thread2 drvs)))
|
| 79 | (thread3 (begin
|
| 80 | (sleep 1)
|
| 81 | (builder 'thread3 drvs))))
|
| 82 |
|
| 83 | |
| 84 | |
| 85 | (let ((deadline (+ (current-time) 120)))
|
| 86 | (list (join-thread thread1 deadline 'timeout)
|
| 87 | (join-thread thread2 deadline 'timeout)
|
| 88 | (join-thread thread3 deadline 'timeout)))))
|
| 89 |
|
| 90 | (test-end)
|