summaryrefslogtreecommitdiff
path: root/tests/publish.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-04-17 23:13:40 +0200
committerLudovic Courtès <ludo@gnu.org>2017-04-18 23:18:41 +0200
commit00753f7038234a0f5a79be3ec9ab949840a18743 (patch)
tree69dd76db7c047953fd256933d399d3f6f0441e93 /tests/publish.scm
parent339a79fd6aec74f0b7520440e01b8bf79eca73e7 (diff)
publish: Add '--cache' and '--workers'.
Fixes <http://bugs.gnu.org/26201>. Reported by <dian_cecht@zoho.com>. These options allow nars to be "baked" off-line and cached instead of being compressed on the fly. As a side-effect, this allows us to provide a 'Content-Length' header for nars. * guix/scripts/publish.scm (show-help, %options): Add '--cache' and '--workers'. (%default-options): Add 'workers'. (nar-cache-file, narinfo-cache-file, run-single-baker): New procedures. (single-baker): New macro. (render-narinfo/cached, bake-narinfo+nar) (render-nar/cached): New procedures. (make-request-handler): Add #:cache and #:pool parameters and honor them. (run-publish-server): Likewise. (guix-publish): Honor '--cache' and '--workers'. * tests/publish.scm ("with cache"): New test. * doc/guix.texi (Invoking guix publish): Document it.
Diffstat (limited to 'tests/publish.scm')
-rw-r--r--tests/publish.scm54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/publish.scm b/tests/publish.scm
index ea0f4a34776..233b71ce93a 100644
--- a/tests/publish.scm
+++ b/tests/publish.scm
@@ -314,4 +314,58 @@ References: ~%"
314 (call-with-input-string "" port-sha256)))))) 314 (call-with-input-string "" port-sha256))))))
315 (response-code (http-get uri)))) 315 (response-code (http-get uri))))
316 316
317(unless (zlib-available?)
318 (test-skip 1))
319(test-equal "with cache"
320 (list #t
321 `(("StorePath" . ,%item)
322 ("URL" . ,(string-append "nar/gzip/" (basename %item)))
323 ("Compression" . "gzip"))
324 200 ;nar/gzip/…
325 #t ;Content-Length
326 200) ;nar/…
327 (call-with-temporary-directory
328 (lambda (cache)
329 (define (wait-for-file file)
330 (let loop ((i 20))
331 (or (file-exists? file)
332 (begin
333 (pk 'wait-for-file file)
334 (sleep 1)
335 (loop (- i 1))))))
336
337 (let ((thread (with-separate-output-ports
338 (call-with-new-thread
339 (lambda ()
340 (guix-publish "--port=6797" "-C2"
341 (string-append "--cache=" cache)))))))
342 (wait-until-ready 6797)
343 (let* ((base "http://localhost:6797/")
344 (part (store-path-hash-part %item))
345 (url (string-append base part ".narinfo"))
346 (nar-url (string-append base "/nar/gzip/" (basename %item)))
347 (cached (string-append cache "/gzip/" (basename %item)
348 ".narinfo"))
349 (nar (string-append cache "/gzip/"
350 (basename %item) ".nar"))
351 (response (http-get url)))
352 (and (= 404 (response-code response))
353 (wait-for-file cached)
354 (let ((body (http-get-port url))
355 (compressed (http-get nar-url))
356 (uncompressed (http-get (string-append base "nar/"
357 (basename %item)))))
358 (list (file-exists? nar)
359 (filter (lambda (item)
360 (match item
361 (("Compression" . _) #t)
362 (("StorePath" . _) #t)
363 (("URL" . _) #t)
364 (_ #f)))
365 (recutils->alist body))
366 (response-code compressed)
367 (= (response-content-length compressed)
368 (stat:size (stat nar)))
369 (response-code uncompressed)))))))))
370
317(test-end "publish") 371(test-end "publish")