-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-test.r3
64 lines (54 loc) · 1.53 KB
/
ci-test.r3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Rebol [
title: "Rebol/WebSocket CI test"
]
system/options/quiet: false
print ["Running test on Rebol build:" mold to-block system/build]
if exists? %websocket.reb [
;; make sure that we load a fresh extension
try [system/modules/websocket: none]
import %websocket.reb
]
ws-decode: :codecs/ws/decode
probe ws-decode codecs/ws/encode #(a: 1 b: ["a" "b"])
print-horizontal-line
print as-green "Launching the server..."
pid: call reduce [to-local-file system/options/boot %server-test.r3]
wait 0:0:1
unless all [
port? try/with [port: open ws://localhost:8081/echo] :print
;; Using custom awake handler...
port/awake: func [event /local port buffer temp] [
sys/log/more 'WS ["== WS-event:" as-red event/type]
port: event/port
buffer: port/extra/buffer ;; used to store unprocessed raw data
switch event/type [
read [
sys/log/debug 'WS ["== raw-data:" as-blue buffer]
temp: ws-decode buffer
if empty? temp [
;; the message is not complete...
sys/log/debug 'WS "== message not complete!"
read port
return false ;; don't wake up yet...
]
sys/log/debug 'WS ["== decoded: " as-green mold temp]
]
]
true
]
port? wait port
port? try/with [write port 'ping] :print
port? try/with [write port "Hello"] :print
port? wait port
port? try/with [read port] :print
port? wait [port 10]
port? try/with [write port 'close] :print
port? wait [port 10]
][
print as-purple "WebSocket test failed!"
]
wait 0.1
print-horizontal-line
print as-green "Stopping the server..."
access-os/set 'pid :pid
wait 0:0:1