blob: ecb981eb87248123300465293003da05947b71bc (
plain)
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
|
# encoding: utf-8
$:.unshift "../lib"
require 'th_mauve'
require 'th_mauve_resolv'
require 'mauve/udp_server'
require 'mauve/server'
class TcMauveUdpServer < Mauve::UnitTest
# Note: this test fires up the UDP socket. It *will* fail if more
# than one instance runs at the same time on the same machine.
include Mauve
def setup
super
Server.instance.packet_buffer.clear # blarg!
@server = UDPServer.instance # blarg!
end
def test_listens
update = generic_update()
before = Time.now
t = Thread.new do @server.__send__(:main_loop) end
sleep(0.2)
sender.send(update)
Timeout.timeout(2) do t.join end
after = Time.now
data, addrinfo, received_at = Server.packet_pop
assert_equal update, Proto::AlertUpdate.new.parse_from_string(data)
assert addrinfo[3], "No client source address!"
assert received_at >= before && received_at <= after, "Received at time was wrong"
end
def test_closes
update = generic_update()
t = @server.run
sleep(0.2)
@server.stop
sleep(0.2)
sender.send(update)
Timeout.timeout(2) do t.join end
assert_nil Server.packet_pop
end
def sender
Sender.new(["#{@server.ip}:#{@server.port}"])
end
def generic_update
update = Proto::AlertUpdate.new
alert = Proto::Alert.new
alert.id = "alertid"
update.alert << alert
update
end
end
|