Improve resource pool destruction
This commit is contained in:
parent
eebb42e7a7
commit
61451907a9
2 changed files with 116 additions and 40 deletions
|
@ -1,32 +1,37 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(knots parallelism)
|
||||
(knots resource-pool))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((resource-pool (make-resource-pool
|
||||
(lambda ()
|
||||
2)
|
||||
1)))
|
||||
(assert-equal
|
||||
(with-resource-from-pool resource-pool
|
||||
res
|
||||
res)
|
||||
2))))
|
||||
(define new-number
|
||||
(let ((val 0))
|
||||
(lambda ()
|
||||
(set! val (1+ val))
|
||||
val)))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((resource-pool (make-resource-pool
|
||||
(lambda ()
|
||||
2)
|
||||
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-equal
|
||||
(with-resource-from-pool resource-pool
|
||||
res
|
||||
res)
|
||||
2))))
|
||||
(assert-true
|
||||
(number?
|
||||
(with-resource-from-pool resource-pool
|
||||
res
|
||||
res))))))
|
||||
|
||||
(let* ((error-constructor
|
||||
(record-constructor &resource-pool-timeout))
|
||||
|
@ -36,4 +41,35 @@
|
|||
(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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue