aboutsummaryrefslogtreecommitdiff
path: root/tests/cache.scm
blob: d495ace2bd761f4b50fb91ff3c0af8f99e3eeb7a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-cache)
  #:use-module (guix cache)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-19)
  #:use-module (srfi srfi-64)
  #:use-module ((guix utils) #:select (call-with-temporary-directory))
  #:use-module (ice-9 match))

(test-begin "cache")

(test-equal "remove-expired-cache-entries"
  '("o" "l" "d")
  (let* ((removed '())
         (now     (time-second (current-time time-monotonic)))
         (ttl     100)
         (stamp   (match-lambda
                    ((or "n" "e" "w") (+ now 100))
                    ((or "o" "l" "d") (- now 100))))
         (delete  (lambda (entry)
                    (set! removed (cons entry removed)))))
    (remove-expired-cache-entries (reverse '("n" "e" "w"
                                             "o" "l" "d"))
                                  #:entry-expiration stamp
                                  #:delete-entry delete)
    removed))

(define-syntax-rule (test-cache-cleanup cache exp ...)
  (call-with-temporary-directory
   (lambda (cache)
     (let* ((deleted '())
            (delete! (lambda (entry)
                       (set! deleted (cons entry deleted)))))
       exp ...
       (maybe-remove-expired-cache-entries cache
                                           (const '("a" "b" "c"))
                                           #:entry-expiration (const 0)
                                           #:delete-entry delete!)
       (reverse deleted)))))

(test-equal "maybe-remove-expired-cache-entries, first cleanup"
  '("a" "b" "c")
  (test-cache-cleanup cache))

(test-equal "maybe-remove-expired-cache-entries, no cleanup needed"
  '()
  (test-cache-cleanup cache
    (call-with-output-file (string-append cache "/last-expiry-cleanup")
      (lambda (port)
        (display (+ (time-second (current-time time-monotonic)) 100)
                 port)))))

(test-equal "maybe-remove-expired-cache-entries, cleanup needed"
  '("a" "b" "c")
  (test-cache-cleanup cache
    (call-with-output-file (string-append cache "/last-expiry-cleanup")
      (lambda (port)
        (display 0 port)))))

(test-equal "maybe-remove-expired-cache-entries, empty cache"
  '("a" "b" "c")
  (test-cache-cleanup cache
    (call-with-output-file (string-append cache "/last-expiry-cleanup")
      (lambda (port)
        (display "" port)))))

(test-equal "maybe-remove-expired-cache-entries, corrupted cache"
  '("a" "b" "c")
  (test-cache-cleanup cache
    (call-with-output-file (string-append cache "/last-expiry-cleanup")
      (lambda (port)
        (display "1\"34657890" port)))))

(test-end "cache")

;;; Local Variables:
;;; eval: (put 'test-cache-cleanup 'scheme-indent-function 1)
;;; End:
pan title='2015-10-13 13:45:51 +0200'>2015-10-13gnu: gcj-4.8, gcj: Update to default GCC version....* gnu/packages/gcc.scm (gcj-4.8): Inherit from "gcc" package and rename variable to... (gcj): ...this new variable. (ecj-bootstrap-4.8): Rename variable to... (ecj-bootstrap): ...this, updating to version 4.9. * gnu/packages/java.scm (icedtea6)[native-inputs]: Replace "gcj-4.8" with "gcj". * gnu/packages/music.scm (tuxguitar)[native-inputs]: Likewise. Ricardo Wurmus 2015-08-29gnu: Use 'install-file' instead of 'mkdir-p' and 'copy-file' in obvious cases....* gnu/packages/bioinformatics.scm (bedtools, bowtie, bwa, hisat, samtools, plink, star): Use 'install-file' instead of 'mkdir-p' + 'copy-file'. * gnu/packages/check.scm (catch-framework): Likewise. * gnu/packages/code.scm (global): Likewise. * gnu/packages/emacs.scm (magit-svn, haskell-mode, emacs-pdf-tools): Likewise. * gnu/packages/engineering.scm (fastcap, fasthenry): Likewise. * gnu/packages/gnuzilla.scm (nss): Likewise. * gnu/packages/guile.scm (guile-minikanren): Likewise. * gnu/packages/java.scm (swt): Likewise. * gnu/packages/make-bootstrap.scm (%static-binaries): Likewise. * gnu/packages/maths.scm (lpsolve): Likewise. * gnu/packages/mp3.scm (mpc123): Likewise. * gnu/packages/ninja.scm (ninja): Likewise. * gnu/packages/python.scm (python-numpy, python-pyparsing): Likewise. * gnu/packages/screen.scm (dtach): Likewise. * gnu/packages/synergy.scm (synergy): Likewise. * gnu/packages/textutils.scm (utf8proc): Likewise. * gnu/packages/version-control.scm (git-test-sequence): Likewise. * gnu/packages/wicd.scm (wicd): Likewise. Ludovic Courtès 2015-07-27gnu: icedtea7: Update to 2.6.1....* gnu/packages/java.scm (icedtea7): Update to 2.6.1. Ricardo Wurmus 2015-06-12gnu: icedtea7: Bootstrap with GCJ....* gnu/packages/java.scm (icedtea7): Bootstrap with GCJ rather than compile with IcedTea6. Ricardo Wurmus 2015-05-12gnu: icedtea6: Add target-dependent include directory to CPATH....* gnu/packages/java.scm (gcj-4.8)[arguments]: Add target-dependent GCJ include directory to CPATH environment variable. Ricardo Wurmus 2015-04-28gnu: Add icedtea7....* gnu/packages/java.scm (icedtea7): New variable. Ricardo Wurmus 2015-04-27gnu: icedtea6: Split test fixing phases....* gnu/packages/java.scm (icedtea6)[arguments]: Split phase 'fix-tests into three phases 'fix-test-framework, 'fix-hotspot-tests, and 'fix-jdk-tests. Ricardo Wurmus 2015-04-21gnu: Add SWT....* gnu/packages/java.scm (swt): New variable. Ricardo Wurmus 2015-04-17Merge branch 'master' into core-updates...Conflicts: gnu-system.am gnu/packages/gstreamer.scm Mark H Weaver 2015-04-15gnu: icedtea6: Update to 1.13.7....* gnu/packages/java.scm (icedtea6): Update to version 1.13.7. Ricardo Wurmus 2015-04-14gnu: Disable RUNPATH validation for packages that use $ORIGIN....* gnu/packages/haskell.scm (ghc)[arguments]: Add #:validate-runpath?. * gnu/packages/julia.scm (julia)[arguments]: Likewise. * gnu/packages/java.scm (icedtea6)[arguments]: Likewise. Ludovic Courtès 2015-03-23gnu: icedtea6: remove commented substitution....* gnu/packages/java.scm (icedtea6): Remove commented substitution. Ricardo Wurmus 2015-03-23gnu: icedtea6: Do not set CC and LD_LIBRARY_PATH....* gnu/packages/java.scm (icedtea6)[arguments]: Do not set CC and LD_LIBRARY_PATH variables. Ricardo Wurmus 2015-03-23gnu: icedtea6: Rename ‘set-paths’ phase to ‘set-additional-paths’...* gnu/packages/java.scm (icedtea6)[arguments]: Rename ‘set-paths’ phase to ‘set-additional-paths’. Ricardo Wurmus 2015-03-23gnu: icedtea6: patch patches in separate build phase....* gnu/packages/java.scm (icedtea6)[arguments]: Move patching of patches from ‘patch-paths’ to new ‘patch-patches’ phase. Ricardo Wurmus 2015-03-23gnu: icedtea6: patch hardcoded objcopy path....* gnu/packages/java.scm (icedtea6)[arguments]: patch Makefile to override DEF_OBJCOPY variable definition. Ricardo Wurmus 2015-03-23gnu: icedtea6: patch ant shebang in unpack phase...* gnu/packages/java.scm (icedtea6)[arguments]: patch bootstrap ant in the `unpack' phase instead of `patch-paths'. Ricardo Wurmus 2015-03-04gnu: Move 'which' to (gnu packages base)....* gnu/packages/which.scm: Remove. * gnu-system.am (GNU_SYSTEM_MODULES): Remove it. * gnu/packages/base.scm (which): New variable. * gnu/packages/aspell.scm, gnu/packages/audio.scm, gnu/packages/autogen.scm, gnu/packages/cdrom.scm, gnu/packages/compression.scm, gnu/packages/datamash.scm, gnu/packages/games.scm, gnu/packages/glib.scm, gnu/packages/gnu-pw-mgr.scm, gnu/packages/gnutls.scm, gnu/packages/gps.scm, gnu/packages/guile.scm, gnu/packages/java.scm, gnu/packages/libevent.scm, gnu/packages/linux.scm, gnu/packages/lisp.scm, gnu/packages/node.scm, gnu/packages/ntp.scm, gnu/packages/orpheus.scm, gnu/packages/pciutils.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/rsync.scm, gnu/packages/sawfish.scm, gnu/packages/scheme.scm, gnu/packages/ssh.scm, gnu/packages/statistics.scm, gnu/packages/texlive.scm, gnu/packages/wdiff.scm: Adjust accordingly. Ludovic Courtès 2015-03-04gnu: icedtea6: split outputs....* gnu/packages/java.scm (icedtea6)[outputs]: Use separate outputs for documentation ("doc"), JDK ("jdk"), and JRE ("out"). * gnu/packages/java.scm (ant)[native-inputs]: Reference "jdk" output of icedtea6 package. * gnu/packages/statistics.scm (r)[inputs]: Reference "jdk" output of icedtea6 package. Ricardo Wurmus 2015-02-19gnu: Add Ant....* gnu/packages/java.scm (ant): New variable. Ricardo Wurmus 2015-01-29gnu: Add IcedTea 6...* gnu/packages/java.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. Ricardo Wurmus