75 lines
1.8 KiB
Scheme
75 lines
1.8 KiB
Scheme
(use-modules (tests)
|
|
(fibers)
|
|
(unit-test)
|
|
(knots parallelism)
|
|
(knots resource-pool))
|
|
|
|
(define new-number
|
|
(let ((val 0))
|
|
(lambda ()
|
|
(set! val (1+ val))
|
|
val)))
|
|
|
|
(run-fibers-for-tests
|
|
(lambda ()
|
|
(let ((resource-pool (make-resource-pool
|
|
new-number
|
|
1)))
|
|
(assert-true
|
|
(number?
|
|
(with-resource-from-pool resource-pool
|
|
res
|
|
res))))))
|
|
|
|
(run-fibers-for-tests
|
|
(lambda ()
|
|
(let ((resource-pool (make-resource-pool
|
|
new-number
|
|
1
|
|
#:add-resources-parallelism 1)))
|
|
(assert-true
|
|
(number?
|
|
(with-resource-from-pool resource-pool
|
|
res
|
|
res))))))
|
|
|
|
(let* ((error-constructor
|
|
(record-constructor &resource-pool-timeout))
|
|
(err
|
|
(error-constructor 'foo)))
|
|
(assert-equal
|
|
(resource-pool-timeout-error-pool err)
|
|
'foo))
|
|
|
|
(run-fibers-for-tests
|
|
(lambda ()
|
|
(let ((resource-pool (make-resource-pool
|
|
new-number
|
|
2)))
|
|
(fibers-for-each
|
|
(lambda _
|
|
(with-resource-from-pool resource-pool
|
|
res
|
|
res))
|
|
(iota 20))
|
|
|
|
(destroy-resource-pool resource-pool))))
|
|
|
|
(run-fibers-for-tests
|
|
(lambda ()
|
|
(let ((resource-pool (make-resource-pool
|
|
new-number
|
|
2
|
|
#:destructor
|
|
(lambda (res)
|
|
#t))))
|
|
(fibers-for-each
|
|
(lambda _
|
|
(with-resource-from-pool resource-pool
|
|
res
|
|
res))
|
|
(iota 20))
|
|
|
|
(destroy-resource-pool resource-pool))))
|
|
|
|
(display "resource-pool test finished successfully\n")
|