Adapt unit test framework for inferred-system
Add unit tests for jobs
This commit is contained in:
parent
f31a433854
commit
c4b1680d2f
4 changed files with 75 additions and 3 deletions
|
|
@ -6,7 +6,7 @@
|
|||
(uiop:define-package :stoe/core/containers
|
||||
(:use :cl :stoe/core/thread)
|
||||
(:export #:queue #:stack #:make-queue #:make-stack
|
||||
#:enqueue #:dequeue #:push-stack #:pop-stack #:peek
|
||||
#:enqueue #:dequeue #:push-stack #:pop-stack #:peek #:size
|
||||
#:safe-queue #:safe-stack
|
||||
#:make-safe-queue #:make-safe-stack))
|
||||
(in-package :stoe/core/containers)
|
||||
|
|
@ -38,6 +38,9 @@
|
|||
(defgeneric peek (container)
|
||||
(:documentation "Return the next element of `container' without removing it."))
|
||||
|
||||
(defgeneric size (container)
|
||||
(:documentation "Return the size of the container."))
|
||||
|
||||
(defun make-queue ()
|
||||
"Make a queue instance."
|
||||
(make-instance 'queue))
|
||||
|
|
@ -66,6 +69,10 @@
|
|||
(with-slots (data) container
|
||||
(first data)))
|
||||
|
||||
(defmethod size ((container container))
|
||||
(with-slots (data) container
|
||||
(length data)))
|
||||
|
||||
(defclass safe-container-mixin ()
|
||||
((lock :initform (make-lock))
|
||||
(waitp :initarg :waitp :accessor safe-container-wait-p))
|
||||
|
|
|
|||
3
stoe.asd
3
stoe.asd
|
|
@ -48,8 +48,7 @@
|
|||
:in-order-to ((test-op (load-op stoe/test))))
|
||||
|
||||
(defsystem stoe/test
|
||||
:depends-on ("stoe/test/all")
|
||||
:perform (load-op :after (op c) (asdf:clear-system c)))
|
||||
:depends-on ("prove" "stoe/test/all"))
|
||||
|
||||
(register-system-packages "stoe/maths/all" '(:maths))
|
||||
(register-system-packages "stoe/core/all" '(:core))
|
||||
|
|
|
|||
9
test/all.lisp
Normal file
9
test/all.lisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(uiop:define-package :stoe/test/all
|
||||
(:nicknames :test)
|
||||
(:use-reexport
|
||||
:stoe/test/jobs))
|
||||
57
test/jobs.lisp
Normal file
57
test/jobs.lisp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#|
|
||||
This file is a part of stoe project.
|
||||
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
||||
|#
|
||||
|
||||
(uiop:define-package :stoe/test/jobs
|
||||
(:use :cl :prove
|
||||
:stoe/core/containers
|
||||
:stoe/core/thread
|
||||
:stoe/core/jobs))
|
||||
(in-package :stoe/test/jobs)
|
||||
|
||||
(stoe/core/jobs::initialize)
|
||||
|
||||
(defun counter (x)
|
||||
(dotimes (i 10 x)
|
||||
(format t "x ~a~%" x)
|
||||
(incf x)))
|
||||
|
||||
(defmacro with-new-job-thread (count &body body)
|
||||
`(progn
|
||||
(dotimes (i ,count)
|
||||
(push-new-job-thread #'stoe/core/jobs::start-job-thread))
|
||||
,@body
|
||||
(mapc (lambda (thread) (terminate-thread thread))
|
||||
stoe/core/jobs::*thread-list*)
|
||||
(sleep 1)
|
||||
(stoe/core/jobs::update 0)))
|
||||
|
||||
(plan 3)
|
||||
|
||||
(with-new-job-thread 1
|
||||
(push-new-job #'counter '(0))
|
||||
(sleep 1)
|
||||
(push-new-job #'counter '(0))
|
||||
(sleep 1)
|
||||
(push-new-job #'counter '(0))
|
||||
(sleep 1))
|
||||
(is (size stoe/core/jobs::*job-queue*) 0 "1 thread, 3 jobs, 1 at a time.")
|
||||
|
||||
(push-new-job #'counter '(0))
|
||||
(push-new-job #'counter '(0))
|
||||
(push-new-job #'counter '(0))
|
||||
(with-new-job-thread 2
|
||||
(sleep 1))
|
||||
(is (size stoe/core/jobs::*job-queue*) 0 "1 thread, 3 jobs, all at once.")
|
||||
|
||||
(with-new-job-thread 3
|
||||
(push-new-job #'counter '(0))
|
||||
(push-new-job #'counter '(0))
|
||||
(push-new-job #'counter '(0))
|
||||
(sleep 1))
|
||||
(is (size stoe/core/jobs::*job-queue*) 0 "3 threads, 3 jobs, all at once.")
|
||||
|
||||
(finalize)
|
||||
|
||||
(stoe/core/jobs::finalize)
|
||||
Loading…
Add table
Reference in a new issue