summaryrefslogtreecommitdiff
path: root/tests/cache.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-07-16 11:03:16 +0200
committerLudovic Courtès <ludo@gnu.org>2024-08-21 00:52:39 +0200
commitd921c742b774a9f0a016f3db6442d5c58a330c92 (patch)
tree398620edbdfe9b97e25c157790bfca6166b58fde /tests/cache.scm
parent96cd163c14e68c66c6a4cf0b18261fc454f8c1ba (diff)
cache: Avoid cache cleanup storms from concurrent processes.
Reported by Christopher Baines <guix@cbaines.net>. * guix/cache.scm (maybe-remove-expired-cache-entries): Define ‘expiry-port’; create it with ‘lock-file’. Change ‘last-expiry-date’ accordingly. Write timestamp straight to ‘expiry-port’. * tests/cache.scm ("maybe-remove-expired-cache-entries, cleanup needed but lock taken"): New test. Change-Id: I22441d9d2c4a339d3d3878de131864db5a0ae826
Diffstat (limited to 'tests/cache.scm')
-rw-r--r--tests/cache.scm30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/cache.scm b/tests/cache.scm
index d495ace2bd7..e8ad083d402 100644
--- a/tests/cache.scm
+++ b/tests/cache.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017, 2020 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2017, 2020, 2024 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2022 Simon Tournier <zimon.toutoune@gmail.com> 3;;; Copyright © 2022 Simon Tournier <zimon.toutoune@gmail.com>
4;;; 4;;;
5;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
@@ -22,7 +22,9 @@
22 #:use-module (srfi srfi-1) 22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-19) 23 #:use-module (srfi srfi-19)
24 #:use-module (srfi srfi-64) 24 #:use-module (srfi srfi-64)
25 #:use-module ((guix build syscalls) #:select (lock-file))
25 #:use-module ((guix utils) #:select (call-with-temporary-directory)) 26 #:use-module ((guix utils) #:select (call-with-temporary-directory))
27 #:use-module ((rnrs io ports) #:select (get-string-all))
26 #:use-module (ice-9 match)) 28 #:use-module (ice-9 match))
27 29
28(test-begin "cache") 30(test-begin "cache")
@@ -75,6 +77,32 @@
75 (lambda (port) 77 (lambda (port)
76 (display 0 port))))) 78 (display 0 port)))))
77 79
80(let ((pid #f))
81 (test-equal "maybe-remove-expired-cache-entries, cleanup needed but lock taken"
82 '()
83 (test-cache-cleanup cache
84 (let ((in+out (pipe)))
85 (match (primitive-fork)
86 (0 (dynamic-wind
87 (const #t)
88 (lambda ()
89 (close-port (car in+out))
90 (let ((port (lock-file
91 (string-append cache "/last-expiry-cleanup"))))
92 (display 0 port)
93 (display "done!\n" (cdr in+out))
94 (close-port (cdr in+out))
95 (sleep 100)))
96 (lambda ()
97 (primitive-exit 0))))
98 (n
99 (set! pid n)
100 (close-port (cdr in+out))
101 (pk 'chr (get-string-all (car in+out)))
102 (close-port (car in+out)))))))
103
104 (when pid (kill pid SIGKILL)))
105
78(test-equal "maybe-remove-expired-cache-entries, empty cache" 106(test-equal "maybe-remove-expired-cache-entries, empty cache"
79 '("a" "b" "c") 107 '("a" "b" "c")
80 (test-cache-cleanup cache 108 (test-cache-cleanup cache