File: test.py

package info (click to toggle)
libaws 20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,656 kB
  • sloc: ada: 95,505; python: 2,270; ansic: 1,017; makefile: 829; xml: 235; javascript: 202; java: 112; sh: 106
file content (82 lines) | stat: -rw-r--r-- 1,749 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from test_support import *
from websocket import create_connection
from time import sleep

build('websock_control')
Server = Run(['./websock_control'], output='./server-output', bg=True)

# read line until we find the server port
while True:
    line = open('server-output').readline()
    if line[0:5] == 'PORT:':
        port = line[line.find(':')+1:].strip()
        break

# websocket client application
ws1 = create_connection("ws://127.0.0.1:"+port+"/echo1")

# Receiving Open connect message, 2 short messages
for J in range(1, 4):
    result = ws1.recv()
    print result

# Sending  messages and receiving echo
for J in range(1, 3):
    ws1.send("ws1: client message %d" % J)
    result = ws1.recv()
    print result

sleep(3)

# create a new websocket

ws2 = create_connection("ws://127.0.0.1:"+port+"/echo2")

# the open message
for J in range(1, 2):
    result = ws2.recv()
    print result

for J in range(1, 3):
    ws2.send("ws2: client message %d" % J)
    result = ws2.recv()
    print result

# create a new websocket

sleep(1)

try:
    ws3 = create_connection("ws://127.0.0.1:"+port+"/echo3")

    # the open message
    for J in range(1, 2):
        result = ws3.recv()
        print result

    for J in range(1, 3):
        ws3.send("ws3: client message %d" % J)
        result = ws3.recv()
        print result

    ws3.close()
except:
    print ("exception for ws3")

ws1.close()
ws2.close()

# for normal ending of test
ws = create_connection("ws://127.0.0.1:"+port+"/echo1")
ws.send("END_TEST")
ws.close()

# check server output
res = Server.wait()
print "Server ends with status %d" % res

print "Server output:"
lines = sorted(open('server-output').readlines())
for l in lines:
    if l[0:5] != 'PORT:':
        print l