dnsruby 1.55 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -0
  3. data/Rakefile +30 -29
  4. data/demo/axfr.rb +93 -93
  5. data/demo/check_soa.rb +99 -99
  6. data/demo/check_zone.rb +59 -59
  7. data/demo/digdlv.rb +43 -43
  8. data/demo/digroot.rb +34 -34
  9. data/demo/example_recurse.rb +14 -14
  10. data/demo/mresolv.rb +30 -30
  11. data/demo/mx.rb +31 -31
  12. data/demo/rubydig.rb +37 -37
  13. data/demo/to_resolve.txt +3088 -3088
  14. data/demo/trace_dns.rb +46 -46
  15. data/lib/dnsruby.rb +161 -526
  16. data/lib/dnsruby/DNS.rb +305 -0
  17. data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
  18. data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
  19. data/lib/dnsruby/code_mappers.rb +295 -0
  20. data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
  21. data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
  22. data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
  23. data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
  24. data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
  25. data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
  26. data/lib/dnsruby/message/decoder.rb +164 -0
  27. data/lib/dnsruby/message/encoder.rb +75 -0
  28. data/lib/dnsruby/message/header.rb +249 -0
  29. data/lib/dnsruby/message/message.rb +629 -0
  30. data/lib/dnsruby/message/question.rb +86 -0
  31. data/lib/dnsruby/message/section.rb +96 -0
  32. data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
  33. data/lib/dnsruby/packet_sender.rb +661 -0
  34. data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
  35. data/lib/dnsruby/resolv.rb +113 -0
  36. data/lib/dnsruby/resolver.rb +1192 -0
  37. data/lib/dnsruby/resource/A.rb +56 -0
  38. data/lib/dnsruby/resource/AAAA.rb +54 -0
  39. data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
  40. data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
  41. data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
  42. data/lib/dnsruby/resource/DLV.rb +27 -0
  43. data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
  44. data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
  45. data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
  46. data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
  47. data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
  48. data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
  49. data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
  50. data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
  51. data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
  52. data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
  53. data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
  54. data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
  55. data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
  56. data/lib/dnsruby/resource/NSEC.rb +275 -0
  57. data/lib/dnsruby/resource/NSEC3.rb +332 -0
  58. data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
  59. data/lib/dnsruby/resource/OPT.rb +272 -0
  60. data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
  61. data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
  62. data/lib/dnsruby/resource/RR.rb +421 -0
  63. data/lib/dnsruby/resource/RRSIG.rb +275 -0
  64. data/lib/dnsruby/resource/RRSet.rb +190 -0
  65. data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
  66. data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
  67. data/lib/dnsruby/resource/SPF.rb +29 -0
  68. data/lib/dnsruby/resource/SRV.rb +112 -0
  69. data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
  70. data/lib/dnsruby/resource/TKEY.rb +163 -0
  71. data/lib/dnsruby/resource/TSIG.rb +593 -0
  72. data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
  73. data/lib/dnsruby/resource/X25.rb +55 -0
  74. data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
  75. data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
  76. data/lib/dnsruby/resource/resource.rb +25 -0
  77. data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
  78. data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
  79. data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
  80. data/lib/dnsruby/the_log.rb +44 -0
  81. data/lib/dnsruby/update.rb +278 -0
  82. data/lib/dnsruby/validator_thread.rb +124 -0
  83. data/lib/dnsruby/version.rb +3 -0
  84. data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
  85. data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
  86. data/test/spec_helper.rb +16 -0
  87. data/test/tc_axfr.rb +31 -34
  88. data/test/tc_cache.rb +32 -32
  89. data/test/tc_dlv.rb +28 -28
  90. data/test/tc_dns.rb +73 -76
  91. data/test/tc_dnskey.rb +31 -32
  92. data/test/tc_dnsruby.rb +50 -44
  93. data/test/tc_ds.rb +36 -36
  94. data/test/tc_escapedchars.rb +252 -255
  95. data/test/tc_hash.rb +17 -21
  96. data/test/tc_header.rb +48 -57
  97. data/test/tc_hip.rb +19 -22
  98. data/test/tc_ipseckey.rb +18 -21
  99. data/test/tc_keith.rb +300 -0
  100. data/test/tc_message.rb +87 -0
  101. data/test/tc_misc.rb +83 -87
  102. data/test/tc_name.rb +81 -84
  103. data/test/tc_naptr.rb +18 -21
  104. data/test/tc_nsec.rb +55 -55
  105. data/test/tc_nsec3.rb +23 -24
  106. data/test/tc_nsec3param.rb +20 -21
  107. data/test/tc_packet.rb +90 -93
  108. data/test/tc_packet_unique_push.rb +48 -51
  109. data/test/tc_question.rb +30 -33
  110. data/test/tc_queue.rb +16 -17
  111. data/test/tc_recur.rb +16 -17
  112. data/test/tc_res_config.rb +38 -41
  113. data/test/tc_res_env.rb +29 -32
  114. data/test/tc_res_file.rb +26 -29
  115. data/test/tc_res_opt.rb +62 -65
  116. data/test/tc_resolver.rb +287 -242
  117. data/test/tc_rr-opt.rb +70 -63
  118. data/test/tc_rr-txt.rb +68 -71
  119. data/test/tc_rr-unknown.rb +45 -48
  120. data/test/tc_rr.rb +76 -70
  121. data/test/tc_rrset.rb +21 -22
  122. data/test/tc_rrsig.rb +19 -20
  123. data/test/tc_single_resolver.rb +294 -297
  124. data/test/tc_soak.rb +199 -202
  125. data/test/tc_soak_base.rb +29 -34
  126. data/test/tc_sshfp.rb +20 -23
  127. data/test/tc_tcp.rb +32 -35
  128. data/test/tc_tkey.rb +41 -44
  129. data/test/tc_tsig.rb +81 -84
  130. data/test/tc_update.rb +108 -111
  131. data/test/tc_validator.rb +29 -29
  132. data/test/tc_verifier.rb +81 -82
  133. data/test/ts_dnsruby.rb +16 -15
  134. data/test/ts_offline.rb +62 -63
  135. data/test/ts_online.rb +115 -115
  136. metadata +155 -90
  137. data/README +0 -59
  138. data/lib/Dnsruby/DNS.rb +0 -305
  139. data/lib/Dnsruby/PacketSender.rb +0 -656
  140. data/lib/Dnsruby/Resolver.rb +0 -1189
  141. data/lib/Dnsruby/TheLog.rb +0 -44
  142. data/lib/Dnsruby/message.rb +0 -1230
  143. data/lib/Dnsruby/resource/A.rb +0 -56
  144. data/lib/Dnsruby/resource/AAAA.rb +0 -54
  145. data/lib/Dnsruby/resource/DLV.rb +0 -27
  146. data/lib/Dnsruby/resource/NSEC.rb +0 -298
  147. data/lib/Dnsruby/resource/NSEC3.rb +0 -340
  148. data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
  149. data/lib/Dnsruby/resource/OPT.rb +0 -213
  150. data/lib/Dnsruby/resource/RRSIG.rb +0 -275
  151. data/lib/Dnsruby/resource/SPF.rb +0 -29
  152. data/lib/Dnsruby/resource/SRV.rb +0 -112
  153. data/lib/Dnsruby/resource/TKEY.rb +0 -163
  154. data/lib/Dnsruby/resource/TSIG.rb +0 -593
  155. data/lib/Dnsruby/resource/X25.rb +0 -55
  156. data/lib/Dnsruby/resource/resource.rb +0 -678
  157. data/lib/Dnsruby/update.rb +0 -278
  158. data/lib/Dnsruby/validator_thread.rb +0 -124
data/test/tc_soak.rb CHANGED
@@ -1,203 +1,200 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
- begin
17
- require 'rubygems'
18
- rescue LoadError
19
- end
20
- require 'test/unit'
21
- require 'dnsruby'
22
- begin
23
- require 'test/tc_single_resolver'
24
- rescue LoadError
25
- require 'tc_single_resolver'
26
- end
27
- begin
28
- require 'test/tc_soak_base'
29
- rescue LoadError
30
- require 'tc_soak_base'
31
- end
32
- include Dnsruby
33
- # This class tries to soak test the Dnsruby library.
34
- # It can't do this very well, owing to the small number of sockets allowed to be open simultaneously.
35
- # @TODO@ Future versions of dnsruby will allow random streaming over a fixed number of (cycling) random sockets,
36
- # so this test can be beefed up considerably at that point.
37
- # @todo@ A test DNS server running on localhost is really needed here
38
- class TestSingleResolverSoak < Test::Unit::TestCase
39
-
40
- def test_many_asynchronous_queries_one_single_resolver
41
- run_many_asynch_queries_test_single_res(1)
42
- end
43
-
44
- def test_many_asynchronous_queries_many_single_resolvers
45
- run_many_asynch_queries_test_single_res(50)
46
- end
47
-
48
- def run_many_asynch_queries_test_single_res(num_resolvers)
49
- q = Queue.new
50
- resolvers = []
51
- timed_out = 0
52
- query_count = 0
53
- num_resolvers.times do |n|
54
- resolvers.push(SingleResolver.new)
55
- resolvers[n].packet_timeout=4
56
- end
57
- res_pos = 0
58
- start = Time.now
59
- # @todo@ On windows, MAX_FILES is 256. This means that we have to limit
60
- # this test while we're not using single sockets.
61
- # We run four queries per iteration, so we're limited to 64 runs.
62
- 63.times do |i|
63
- rr_count = 0
64
- TestSoakBase::Rrs.each do |data|
65
- rr_count+=1
66
- res = resolvers[res_pos]
67
- res_pos=+1
68
- if (res_pos >= num_resolvers)
69
- res_pos = 0
70
- end
71
- res.send_async(Message.new(data[:name], data[:type]), q, [i,rr_count])
72
- # p "Sent #{i}, #{rr_count}, Queue #{q}"
73
- query_count+=1
74
- end
75
- end
76
- query_count.times do |i|
77
- id,ret, error = q.pop
78
- if (error.class == ResolvTimeout)
79
- timed_out+=1
80
- elsif (ret.class != Message)
81
- p "ERROR RETURNED : #{error}"
82
- end
83
-
84
- end
85
- stop=Time.now
86
- time_taken=stop-start
87
- p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
88
- assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
89
- end
90
-
91
-
92
- def test_many_threads_on_one_single_resolver_synchronous
93
- # Test multi-threaded behaviour
94
- # Check the header IDs to make sure they're all different
95
- threads = Array.new
96
- res = SingleResolver.new
97
- ids = []
98
- mutex = Mutex.new
99
- timed_out = 0
100
- query_count = 0
101
- res.packet_timeout=4
102
- start=Time.now
103
- # Windows limits us to 256 sockets
104
- num_times=250
105
- if (/java/ =~ RUBY_PLATFORM)
106
- # JRuby threads are native threads, so let's not go too mad!
107
- num_times=50
108
- end
109
- num_times.times do |i|
110
- threads[i] = Thread.new{
111
- 40.times do |j|
112
- TestSoakBase::Rrs.each do |data|
113
- mutex.synchronize do
114
- query_count+=1
115
- end
116
- packet=nil
117
- begin
118
- packet = res.query(data[:name], data[:type])
119
- rescue ResolvTimeout
120
- mutex.synchronize {
121
- timed_out+=1
122
- }
123
- next
124
- end
125
- assert(packet)
126
- ids.push(packet.header.id)
127
- assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
128
- end
129
- end
130
- }
131
- end
132
- threads.each do |thread|
133
- thread.join
134
- end
135
- stop=Time.now
136
- time_taken=stop-start
137
- p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
138
- # check_ids(ids) # only do this if we expect all different IDs - e.g. if we stream over a single socket
139
- assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
140
- end
141
-
142
- def check_ids(ids)
143
- ids.sort!
144
- count = 0
145
- ids.each do |id|
146
- count+=1
147
- if (count < ids.length-1)
148
- assert(ids[count+1] != id, "Two identical header ids used!")
149
- end
150
- end
151
- end
152
-
153
- def test_many_threads_on_many_single_resolvers
154
- # Test multi-threaded behaviour
155
- # @todo@ Check the header IDs to make sure they're all different
156
- threads = Array.new
157
- mutex = Mutex.new
158
- timed_out = 0
159
- query_count = 0
160
- start=Time.now
161
- num_times=250
162
- if (/java/ =~ RUBY_PLATFORM)
163
- # JRuby threads are native threads, so let's not go too mad!
164
- num_times=50
165
- end
166
- num_times.times do |i|
167
- threads[i] = Thread.new{
168
- res = SingleResolver.new
169
- res.packet_timeout=4
170
- 40.times do |j|
171
- TestSoakBase::Rrs.each do |data|
172
- mutex.synchronize do
173
- query_count+=1
174
- end
175
- q = Queue.new
176
- res.send_async(Message.new(data[:name], data[:type]), q, [i,j])
177
- id, packet, error = q.pop
178
- if (error.class == ResolvTimeout)
179
- mutex.synchronize {
180
- timed_out+=1
181
- }
182
- next
183
- elsif (packet.class!=Message)
184
- p "ERROR! #{error}"
185
- end
186
-
187
- assert(packet)
188
- assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
189
- end
190
- end
191
- }
192
- end
193
- threads.each do |thread|
194
- thread.join
195
- end
196
- stop=Time.now
197
- time_taken=stop-start
198
- p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
199
- assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
200
- end
201
-
202
-
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ require_relative 'spec_helper'
18
+
19
+ begin
20
+ require 'test/tc_single_resolver'
21
+ rescue LoadError
22
+ require 'tc_single_resolver'
23
+ end
24
+ begin
25
+ require 'test/tc_soak_base'
26
+ rescue LoadError
27
+ require 'tc_soak_base'
28
+ end
29
+ include Dnsruby
30
+ # This class tries to soak test the Dnsruby library.
31
+ # It can't do this very well, owing to the small number of sockets allowed to be open simultaneously.
32
+ # @TODO@ Future versions of dnsruby will allow random streaming over a fixed number of (cycling) random sockets,
33
+ # so this test can be beefed up considerably at that point.
34
+ # @todo@ A test DNS server running on localhost is really needed here
35
+ class TestSingleResolverSoak < Minitest::Test
36
+
37
+ def test_many_asynchronous_queries_one_single_resolver
38
+ run_many_asynch_queries_test_single_res(1)
39
+ end
40
+
41
+ def test_many_asynchronous_queries_many_single_resolvers
42
+ run_many_asynch_queries_test_single_res(50)
43
+ end
44
+
45
+ def run_many_asynch_queries_test_single_res(num_resolvers)
46
+ q = Queue.new
47
+ resolvers = []
48
+ timed_out = 0
49
+ query_count = 0
50
+ num_resolvers.times do |n|
51
+ resolvers.push(SingleResolver.new)
52
+ resolvers[n].packet_timeout=4
53
+ end
54
+ res_pos = 0
55
+ start = Time.now
56
+ # @todo@ On windows, MAX_FILES is 256. This means that we have to limit
57
+ # this test while we're not using single sockets.
58
+ # We run four queries per iteration, so we're limited to 64 runs.
59
+ 63.times do |i|
60
+ rr_count = 0
61
+ TestSoakBase::Rrs.each do |data|
62
+ rr_count+=1
63
+ res = resolvers[res_pos]
64
+ res_pos=+1
65
+ if (res_pos >= num_resolvers)
66
+ res_pos = 0
67
+ end
68
+ res.send_async(Message.new(data[:name], data[:type]), q, [i,rr_count])
69
+ # p "Sent #{i}, #{rr_count}, Queue #{q}"
70
+ query_count+=1
71
+ end
72
+ end
73
+ query_count.times do |i|
74
+ id,ret, error = q.pop
75
+ if (error.class == ResolvTimeout)
76
+ timed_out+=1
77
+ elsif (ret.class != Message)
78
+ p "ERROR RETURNED : #{error}"
79
+ end
80
+
81
+ end
82
+ stop=Time.now
83
+ time_taken=stop-start
84
+ p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
85
+ assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
86
+ end
87
+
88
+
89
+ def test_many_threads_on_one_single_resolver_synchronous
90
+ # Test multi-threaded behaviour
91
+ # Check the header IDs to make sure they're all different
92
+ threads = Array.new
93
+ res = SingleResolver.new
94
+ ids = []
95
+ mutex = Mutex.new
96
+ timed_out = 0
97
+ query_count = 0
98
+ res.packet_timeout=4
99
+ start=Time.now
100
+ # Windows limits us to 256 sockets
101
+ num_times=250
102
+ if (/java/ =~ RUBY_PLATFORM)
103
+ # JRuby threads are native threads, so let's not go too mad!
104
+ num_times=50
105
+ end
106
+ num_times.times do |i|
107
+ threads[i] = Thread.new{
108
+ 40.times do |j|
109
+ TestSoakBase::Rrs.each do |data|
110
+ mutex.synchronize do
111
+ query_count+=1
112
+ end
113
+ packet=nil
114
+ begin
115
+ packet = res.query(data[:name], data[:type])
116
+ rescue ResolvTimeout
117
+ mutex.synchronize {
118
+ timed_out+=1
119
+ }
120
+ next
121
+ end
122
+ assert(packet)
123
+ ids.push(packet.header.id)
124
+ assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
125
+ end
126
+ end
127
+ }
128
+ end
129
+ threads.each do |thread|
130
+ thread.join
131
+ end
132
+ stop=Time.now
133
+ time_taken=stop-start
134
+ p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
135
+ # check_ids(ids) # only do this if we expect all different IDs - e.g. if we stream over a single socket
136
+ assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
137
+ end
138
+
139
+ def check_ids(ids)
140
+ ids.sort!
141
+ count = 0
142
+ ids.each do |id|
143
+ count+=1
144
+ if (count < ids.length-1)
145
+ assert(ids[count+1] != id, "Two identical header ids used!")
146
+ end
147
+ end
148
+ end
149
+
150
+ def test_many_threads_on_many_single_resolvers
151
+ # Test multi-threaded behaviour
152
+ # @todo@ Check the header IDs to make sure they're all different
153
+ threads = Array.new
154
+ mutex = Mutex.new
155
+ timed_out = 0
156
+ query_count = 0
157
+ start=Time.now
158
+ num_times=250
159
+ if (/java/ =~ RUBY_PLATFORM)
160
+ # JRuby threads are native threads, so let's not go too mad!
161
+ num_times=50
162
+ end
163
+ num_times.times do |i|
164
+ threads[i] = Thread.new{
165
+ res = SingleResolver.new
166
+ res.packet_timeout=4
167
+ 40.times do |j|
168
+ TestSoakBase::Rrs.each do |data|
169
+ mutex.synchronize do
170
+ query_count+=1
171
+ end
172
+ q = Queue.new
173
+ res.send_async(Message.new(data[:name], data[:type]), q, [i,j])
174
+ id, packet, error = q.pop
175
+ if (error.class == ResolvTimeout)
176
+ mutex.synchronize {
177
+ timed_out+=1
178
+ }
179
+ next
180
+ elsif (packet.class!=Message)
181
+ p "ERROR! #{error}"
182
+ end
183
+
184
+ assert(packet)
185
+ assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
186
+ end
187
+ end
188
+ }
189
+ end
190
+ threads.each do |thread|
191
+ thread.join
192
+ end
193
+ stop=Time.now
194
+ time_taken=stop-start
195
+ p "Query count : #{query_count}, #{timed_out} timed out. #{time_taken} time taken"
196
+ assert(timed_out < query_count * 0.1, "#{timed_out} of #{query_count} timed out!")
197
+ end
198
+
199
+
203
200
  end
data/test/tc_soak_base.rb CHANGED
@@ -1,27 +1,22 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
8
  # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
16
 
17
- begin
18
- require 'rubygems'
19
- rescue LoadError
20
- end
21
- require 'test/unit'
22
- require 'dnsruby'
17
+ require_relative 'spec_helper'
23
18
 
24
- class TestSoakBase # < Test::Unit::TestCase
19
+ class TestSoakBase # < Minitest::Test
25
20
  include Dnsruby
26
21
  Rrs = [
27
22
  {
@@ -44,12 +39,12 @@ class TestSoakBase # < Test::Unit::TestCase
44
39
  :type => Types.TXT,
45
40
  :name => 'txt.t.dnsruby.validation-test-servers.nominet.org.uk',
46
41
  :strings => ['Net-DNS']
47
- }
48
- ]
42
+ }
43
+ ]
49
44
 
50
45
  def TestSoakBase.test_continuous_queries_asynch_single_res
51
- # Have two threads looping, with one sending, and one receiving queries.
52
- # Never exceed more than 200 concurrent queries, but make sure they're always running.
46
+ # Have two threads looping, with one sending, and one receiving queries.
47
+ # Never exceed more than 200 concurrent queries, but make sure they're always running.
53
48
  outstanding_limit = 1
54
49
  num_loops = 2000
55
50
  num_sent = 0
@@ -76,7 +71,7 @@ class TestSoakBase # < Test::Unit::TestCase
76
71
  }
77
72
  end
78
73
  end
79
-
74
+
80
75
  }
81
76
  receiver = Thread.new{
82
77
  (num_loops*4).times do |i|
@@ -86,7 +81,7 @@ class TestSoakBase # < Test::Unit::TestCase
86
81
  }
87
82
  if (error.class == ResolvTimeout)
88
83
  timed_out+=1
89
- # p "Number #{i} timed out!"
84
+ # p "Number #{i} timed out!"
90
85
  elsif (ret.class != Message)
91
86
  Dnsruby.log.debug("tc_single_resolver : Query #{i} ERROR RETURNED : #{error.class}, #{error}")
92
87
  end
@@ -100,10 +95,10 @@ class TestSoakBase # < Test::Unit::TestCase
100
95
  p "Query count : #{num_sent}, #{timed_out} timed out. #{time_taken} time taken"
101
96
  assert(timed_out < num_sent * 0.1, "#{timed_out} of #{num_sent} timed out!")
102
97
  end
103
-
98
+
104
99
  def TestSoakBase.test_continuous_queries_asynch_resolver
105
- # Have two threads looping, with one sending, and one receiving queries.
106
- # Never exceed more than 250 concurrent queries, but make sure they're always running.
100
+ # Have two threads looping, with one sending, and one receiving queries.
101
+ # Never exceed more than 250 concurrent queries, but make sure they're always running.
107
102
  num_loops = 1000
108
103
  num_sent = 0
109
104
  q = Queue.new
@@ -113,9 +108,9 @@ class TestSoakBase # < Test::Unit::TestCase
113
108
  num_in_progress = 0
114
109
  sender = Thread.new{
115
110
  res = Resolver.new
116
- # On windows, MAX_FILES is 256. This means that we have to limit
117
- # this test while we're not using single sockets.
118
- # We run four queries per iteration, so we're limited to 64 runs.
111
+ # On windows, MAX_FILES is 256. This means that we have to limit
112
+ # this test while we're not using single sockets.
113
+ # We run four queries per iteration, so we're limited to 64 runs.
119
114
  num_loops.times do |i|
120
115
  while (mutex.synchronize{num_in_progress> 50}) do # One query has several sockets in Resolver
121
116
  sleep(0.01)
@@ -136,7 +131,7 @@ class TestSoakBase # < Test::Unit::TestCase
136
131
  }
137
132
  if (error.class == ResolvTimeout)
138
133
  timed_out+=1
139
- # p "Number #{i} timed out!"
134
+ # p "Number #{i} timed out!"
140
135
  elsif (ret.class != Message)
141
136
  error_count+=1
142
137
  Dnsruby.log.error("tc_single_resolver : Query #{i} ERROR RETURNED : #{error.class}, #{error}")