1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
3 ;;; --- iolib.multiplex test suite.
6 (in-package :iolib-tests
)
8 (in-suite :iolib.multiplex
)
10 (defmacro with-event-base
/for-each-mux
((base &rest initargs
) &body body
)
12 (dolist (mux (mapcar #'cdr
*available-multiplexers
*) failed-list
)
14 (with-event-base (,base
:mux mux
,@initargs
)
17 (push (cons mux err
) failed-list
))))))
19 (test (timeout.1 :compile-at
:definition-time
)
21 (with-event-base/for-each-mux
(base)
22 (event-dispatch base
:timeout
0))))
24 (test (timeout.2 :compile-at
:definition-time
)
26 (with-event-base/for-each-mux
(base)
28 (add-timer base
(lambda () (setq cb
:timeout
)) 30)
29 (event-dispatch base
:timeout
0)
30 (assert (null cb
))))))
32 (test (timeout.3 :compile-at
:definition-time
)
34 (with-event-base/for-each-mux
(base)
36 (add-timer base
(lambda () (setq cb
:timeout
)) 0)
37 (event-dispatch base
:one-shot t
)
38 (assert (eq cb
:timeout
))))))
40 ;;; regression test: timeouts' absolute times used used to be
41 ;;; incremented with the relative time ad infinitum.
42 (test (timeout.4 :compile-at
:definition-time
)
44 (with-event-base/for-each-mux
(base)
46 (add-timer base
(lambda () (setq cb
:timeout
)) 1.5)
47 (event-dispatch base
:timeout
2)
48 (assert (eq cb
:timeout
))))))
50 (defun timeout-cb (fd event
)
51 (declare (ignore fd event
))
54 (defmacro waiting-for-event
((base fd event-type
) &body body
)
55 (with-gensyms (fd-arg event-arg error-arg
)
58 (set-io-handler ,base
,fd
,event-type
59 (lambda (,fd-arg
,event-arg
,error-arg
)
60 (declare (ignore ,error-arg
))
61 (when (eq ,event-arg
:error
)
62 (error "error with ~A" ,fd-arg
))
65 (event-dispatch ,base
:one-shot t
)))))
67 ;;; FIXME: doesn't work with SELECT.
68 ;;; where ? it works here, on Linux. SIONESCU 2007.12.02
69 (test (event-base-with-open-sockets :compile-at
:definition-time
)
72 (with-event-base (base)
73 (with-open-socket (passive :address-family
:ipv4
:connect
:passive
74 :local-host
+ipv4-unspecified
+)
75 (with-open-socket (active :address-family
:ipv4
76 :remote-port
(local-port passive
)
77 :remote-host
+ipv4-unspecified
+)
78 (add-timer base
#'timeout-cb
5)
80 (waiting-for-event (base (fd-of passive
) :read
)
81 (setq peer
(accept-connection passive
)))
82 (assert (socket-open-p peer
))
83 (send-to active
#(1 2 3 4))
84 (waiting-for-event (base (fd-of peer
) :read
)
85 (multiple-value-bind (v n
)
86 (receive-from peer
:size
5)
88 (assert (equalp v
#(1 2 3 4 0))))
89 (return-from test t
)))))