forked from avalanche123/uvrb
- Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathudp_spec.rb
73 lines (61 loc) · 1.57 KB
/
udp_spec.rb
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
require'libuv'
require'thread'
describeLibuv::UDPdo
before:eachdo
@log=[]
@general_failure=[]
@reactor=Libuv::Reactor.new
@server=@reactor.udp
@client=@reactor.udp
@timeout=@reactor.timerdo
@reactor.stop
@general_failure << "test timed out"
end
@timeout.start(5000)
@reactor.notifierdo |error,context|
begin
@general_failure << "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n")iferror.backtrace}\n"
rescueException=>e
@general_failure << "error in logger #{e.inspect}"
end
end
@reactor.all(@server,@client,@timeout).catchdo |reason|
@general_failure << reason.inspect
end
end
describe'basic client server'do
it"should send a ping and return a pong",:network=>truedo
@reactor.run{ |reactor|
@server.bind('127.0.0.1',34567)
@server.progressdo |data,ip,port,server|
@log << data
server.send(ip,port,'pong')
end
@server.start_read
# catch errors
@server.catchdo |reason|
@general_failure << reason.inspect
end
# connect client to server
@client.bind('127.0.0.1',34568)
@client.progressdo |data,ip,port,client|
@log << data
client.close
end
@client.start_read
@client.send('127.0.0.1',34567,'ping')
# catch errors
@client.catchdo |reason|
@general_failure << reason.inspect
end
# close the handle
@client.finallydo
@server.close
@reactor.stop
end
}
expect(@log).toeq(['ping','pong'])
expect(@general_failure).toeq([])
end
end
end