From dbb74b58141d60fad7d1fa6eabaeef39afae81dc Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 11 Oct 2018 16:03:03 -0600 Subject: [PATCH] doc and test updates for a sandbox repair --- .../scribblings/reference/sandbox.scrbl | 15 +++++++++++---- pkgs/racket-test/tests/racket/sandbox.rkt | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/sandbox.scrbl b/pkgs/racket-doc/scribblings/reference/sandbox.scrbl index 55b5bafc0e..f8096aded4 100644 --- a/pkgs/racket-doc/scribblings/reference/sandbox.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sandbox.scrbl @@ -715,7 +715,7 @@ The memory limit that is specified by this parameter applies to each individual evaluation, but not to the whole sandbox --- that limit is specified via @racket[sandbox-memory-limit]. When the global limit is exceeded, the sandbox is terminated, but when the per-evaluation limit -is exceeded the @exnraise[exn:fail:resource]. For example, say that +is exceeded, an exception recognizable by @racket[exn:fail:resource?] is raised. For example, say that you evaluate an expression like @racketblock[ (for ([i (in-range 1000)]) @@ -1040,7 +1040,7 @@ checked at the time that a sandbox evaluator is created.} Executes the given @racket[thunk] with memory and time restrictions: if execution consumes more than @racket[mb] megabytes or more than @racket[secs] @tech{shallow time} seconds, then the computation is -aborted and the @exnraise[exn:fail:resource]. Otherwise the result of +aborted and an exception recognizable by @racket[exn:fail:resource?] is raised. Otherwise, the result of the thunk is returned as usual (a value, multiple values, or an exception). Each of the two limits can be @racket[#f] to indicate the absence of a limit. See also @racket[custodian-limit-memory] for @@ -1059,8 +1059,15 @@ A macro version of @racket[call-with-limits].} @defproc[(call-with-deep-time-limit [secs exact-nonnegative-integer?] [thunk (-> any)]) any]{ - Executes the given @racket[thunk] with @tech{deep time} restrictions. -} +Executes the given @racket[thunk] with @tech{deep time} restrictions, +and returns the values produced by @racket[thunk]. + +The given @racket[thunk] is run in a new thread. If it errors or if +the thread terminates returning a value, then @racket[(values)] is +returned. + +@history[#:changed "1.1" @elem{Changed to return @racket[thunk]'s result + if it completes normally.}]} @defform[(with-deep-time-limit secs-expr body ...)]{ diff --git a/pkgs/racket-test/tests/racket/sandbox.rkt b/pkgs/racket-test/tests/racket/sandbox.rkt index d36947eaa9..de85523988 100644 --- a/pkgs/racket-test/tests/racket/sandbox.rkt +++ b/pkgs/racket-test/tests/racket/sandbox.rkt @@ -9,11 +9,19 @@ (require rackunit) (define n 1) - (check-not-exn - (λ () - (with-deep-time-limit - n - (sleep (sub1 n))))) + (check-equal? + (with-deep-time-limit + n + (begin (sleep (sub1 n)) 'done)) + 'done) + (check-equal? + (call-with-values + (lambda () + (with-deep-time-limit + n + (kill-thread (current-thread)))) + list) + null) (check-exn exn:fail:resource:time? (λ ()