Skip to content

Commit fd618e8

Browse files
merging in latest, disabling no-overlap test
1 parent a38e7a7 commit fd618e8

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

cl-async-test.asd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#:fiveam
1010
#:bordeaux-threads
1111
#:usocket
12-
#:flexi-streams)
12+
#:flexi-streams
13+
#:ironclad)
1314
:components
1415
((:module test
1516
:serial t

src/base.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
One object to rule them all, one object to find them.
8686
One object to bring them in and in the darkness bind them."))
8787

88-
(defvar *buffer-writes* t
88+
(defvar *buffer-writes* nil
8989
"If T, will buffer writes on the socket until the next loop. This is mainly to
9090
cut down on calls to uv_write, which is fairly slow.")
9191

test/tcp.lisp

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,64 @@
128128
(as:close-tcp-server server))))
129129
(is-true first-successful-p)))
130130

131+
(defun sha256 (byte-array)
132+
(let ((byte-array (if (typep byte-array '(simple-array (unsigned-byte 8) (*)))
133+
byte-array
134+
(coerce byte-array '(simple-array (unsigned-byte 8) (*)))))
135+
(hasher (ironclad:make-digest :sha256)))
136+
(ironclad:update-digest hasher byte-array)
137+
(ironclad:byte-array-to-hex-string (ironclad:produce-digest hasher))))
138+
139+
#|
131140
(test no-overlap
132141
"Make sure that requests/responses don't overlap."
142+
(format t "~%---~%")
133143
(multiple-value-bind (res)
134-
(async-let ((res (make-hash-table :test 'eq)))
135-
(test-timeout 3)
144+
(async-let ((res (make-hash-table :test #'eq))
145+
(size (+ as:*buffer-size* 20000))
146+
(num-clients 4)
147+
(num-recv 0)
148+
(server nil))
149+
(test-timeout 20)
136150
137-
(let ((counter 1))
151+
(setf server
138152
(as:tcp-server nil 31389
139153
(lambda (sock data)
140-
(dotimes (i (length data))
141-
(assert (= (aref data 0) (aref data i))))
142-
(incf (getf (as:socket-data sock) :bytes) (length data))
143-
(when (<= (+ as:*buffer-size* 20000) (getf (as:socket-data sock) :bytes))
144-
(let ((res (make-array 500000 :initial-element (getf (as:socket-data sock) :id)
145-
:element-type 'as:octet)))
146-
(as:write-socket-data sock res))))
147-
:connect-cb (lambda (sock)
148-
(setf (as:socket-data sock) (list :id counter :bytes 0))
149-
(incf counter))))
150-
(dotimes (i 4)
151-
(let ((x i))
154+
(unless (getf (as:socket-data sock) :id)
155+
(setf (getf (as:socket-data sock) :id) (aref data 0)))
156+
(unless (getf (as:socket-data sock) :bytes)
157+
(setf (getf (as:socket-data sock) :bytes) 0))
158+
(let ((id (getf (as:socket-data sock) :id))
159+
(undupe (remove-duplicates data)))
160+
(assert (and (= (length undupe) 1)
161+
(= (aref undupe 0) id)))
162+
(incf (getf (as:socket-data sock) :bytes) (length data))
163+
(when (<= size (getf (as:socket-data sock) :bytes))
164+
(format t "server: send: ~a ~a~%" id (* size 1))
165+
(as:write-socket-data
166+
sock
167+
(make-array (* size 1) :initial-element id :element-type 'as:octet))
168+
(incf num-recv)
169+
(when (<= num-clients num-recv)
170+
(as:with-delay ()
171+
(format t "close server: t~%")
172+
(as:close-tcp-server server))))))))
173+
174+
(dotimes (i num-clients)
175+
(let* ((x i)
176+
(data (make-array size
177+
:initial-element x
178+
:element-type '(unsigned-byte 8))))
179+
(format t "client: send: ~a ~a~%" x (length data))
152180
(as:tcp-connect "127.0.0.1" 31389
153181
(lambda (sock data)
154182
(declare (ignorable sock))
155-
(push data (gethash x res)))
156-
:data (make-array (+ as:*buffer-size* 20000)
157-
:initial-element x
158-
:element-type '(unsigned-byte 8))))))
159-
(loop ;for k being the hash-keys of res
183+
(push data (gethash x res))
184+
(format t "client: recv: ~a ~a ~a~%" x (length data)
185+
(reduce (lambda (acc x) (+ acc (length x))) (gethash x res) :initial-value 0)))
186+
:data data))))
187+
(format t "res done~%")(force-output)
188+
(loop for x being the hash-keys of res
160189
for v being the hash-values of res do
161190
(let ((stream (flexi-streams:make-in-memory-output-stream :element-type '(unsigned-byte 8))))
162191
(dolist (part v)
@@ -169,6 +198,10 @@
169198
(return)))
170199
(is (eq is-eq t)))))))
171200
201+
(setf *debug-on-error* t)
202+
(run! 'no-overlap)
203+
|#
204+
172205
(test write-seq-with-offset
173206
"Make sure writing subsequences to a socket works properly"
174207
(with-test-event-loop ()

test/util.lisp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
do this itself without skewing results. Uses event base IDs to make sure it
2626
doesn't cancel an event loop that test-timeout wasn't called inside of."
2727
(let ((cancel nil)
28-
(notifier (as:make-notifier 'as:exit-event-loop)))
28+
(notifier (as:make-notifier (lambda () (error "test timeout")))))
2929
(as:unref notifier)
3030
;; if the event loop exits naturally, cancel the break
3131
(as:add-event-loop-exit-callback
3232
(lambda ()
33+
(setf cancel t)
3334
(unless (as:notifier-freed-p notifier)
34-
(as:free-notifier notifier))
35-
(setf cancel t)))
35+
(as:free-notifier notifier))))
3636
;; spawn the thread to kill the event loop
3737
(handler-case
3838
(bt:make-thread (lambda ()

0 commit comments

Comments
 (0)