Initial commit
This commit is contained in:
commit
2f39c58d6c
27 changed files with 2969 additions and 0 deletions
31
tests/non-blocking.scm
Normal file
31
tests/non-blocking.scm
Normal file
|
@ -0,0 +1,31 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(web uri)
|
||||
(web client)
|
||||
(web response)
|
||||
(knots web-server)
|
||||
(knots non-blocking))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let* ((web-server
|
||||
(run-knots-web-server
|
||||
(lambda (request)
|
||||
(values '((content-type . (text/plain)))
|
||||
"Hello, World!"))
|
||||
#:port 0)) ;; Bind to any port
|
||||
(port
|
||||
(web-server-port web-server))
|
||||
(uri
|
||||
(build-uri 'http #:host "127.0.0.1" #:port port)))
|
||||
|
||||
|
||||
(assert-equal
|
||||
200
|
||||
(response-code
|
||||
(http-get
|
||||
uri
|
||||
#:port (nonblocking-open-socket-for-uri uri)))))))
|
||||
|
||||
(display "non-blocking test finished successfully\n")
|
15
tests/parallelism.scm
Normal file
15
tests/parallelism.scm
Normal file
|
@ -0,0 +1,15 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(knots parallelism))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
1122
|
||||
(apply + (fibers-map
|
||||
(lambda (i)
|
||||
(* 2 i))
|
||||
(iota 34))))))
|
||||
|
||||
(display "parallelism test finished successfully\n")
|
20
tests/promise.scm
Normal file
20
tests/promise.scm
Normal file
|
@ -0,0 +1,20 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(knots parallelism)
|
||||
(knots promise))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((promises
|
||||
(map (lambda (i)
|
||||
(fibers-delay
|
||||
(lambda ()
|
||||
(* i 2))))
|
||||
(iota 10))))
|
||||
|
||||
(assert-equal
|
||||
90
|
||||
(apply + (fibers-map fibers-force promises))))))
|
||||
|
||||
(display "promise test finished successfully\n")
|
22
tests/queue.scm
Normal file
22
tests/queue.scm
Normal file
|
@ -0,0 +1,22 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(fibers channels)
|
||||
(unit-test)
|
||||
(knots queue))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let* ((dest-channel
|
||||
(make-channel))
|
||||
(queue-channel
|
||||
(spawn-queueing-fiber dest-channel)))
|
||||
|
||||
(put-message queue-channel 1)
|
||||
(put-message queue-channel 2)
|
||||
(put-message queue-channel 3)
|
||||
|
||||
(assert-equal 1 (get-message dest-channel))
|
||||
(assert-equal 2 (get-message dest-channel))
|
||||
(assert-equal 3 (get-message dest-channel)))))
|
||||
|
||||
(display "queue test finished successfully\n")
|
18
tests/resource-pool.scm
Normal file
18
tests/resource-pool.scm
Normal file
|
@ -0,0 +1,18 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(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))))
|
||||
|
||||
(display "resource-pool test finished successfully\n")
|
22
tests/timeout.scm
Normal file
22
tests/timeout.scm
Normal file
|
@ -0,0 +1,22 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(knots timeout))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
1
|
||||
(with-fibers-timeout
|
||||
(const 1)
|
||||
#:timeout 10))
|
||||
|
||||
(assert-equal
|
||||
2
|
||||
(with-fibers-timeout
|
||||
(lambda ()
|
||||
(sleep 10))
|
||||
#:timeout 0.1
|
||||
#:on-timeout (const 2)))))
|
||||
|
||||
(display "timeout test finished successfully\n")
|
30
tests/web-server.scm
Normal file
30
tests/web-server.scm
Normal file
|
@ -0,0 +1,30 @@
|
|||
(use-modules (tests)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(web uri)
|
||||
(web client)
|
||||
(web response)
|
||||
(knots web-server)
|
||||
(knots non-blocking))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let* ((web-server
|
||||
(run-knots-web-server
|
||||
(lambda (request)
|
||||
(values '((content-type . (text/plain)))
|
||||
"Hello, World!"))
|
||||
#:port 0)) ;; Bind to any port
|
||||
(port
|
||||
(web-server-port web-server))
|
||||
(uri
|
||||
(build-uri 'http #:host "127.0.0.1" #:port port)))
|
||||
|
||||
(assert-equal
|
||||
200
|
||||
(response-code
|
||||
(http-get
|
||||
uri
|
||||
#:port (nonblocking-open-socket-for-uri uri)))))))
|
||||
|
||||
(display "web-server test finished successfully\n")
|
32
tests/worker-threads.scm
Normal file
32
tests/worker-threads.scm
Normal file
|
@ -0,0 +1,32 @@
|
|||
(use-modules (tests)
|
||||
(srfi srfi-71)
|
||||
(fibers)
|
||||
(unit-test)
|
||||
(knots worker-threads))
|
||||
|
||||
(let ((worker-thread-channel
|
||||
(make-worker-thread-channel
|
||||
(const '())
|
||||
#:parallelism 2)))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
(call-with-worker-thread
|
||||
worker-thread-channel
|
||||
(lambda ()
|
||||
4))
|
||||
4))))
|
||||
|
||||
(let ((process-job
|
||||
count-jobs
|
||||
count-threads
|
||||
list-jobs
|
||||
(create-work-queue
|
||||
2
|
||||
(lambda (i)
|
||||
(* i 2)))))
|
||||
|
||||
(process-job 3))
|
||||
|
||||
(display "worker-threads test finished successfully\n")
|
Loading…
Add table
Add a link
Reference in a new issue