mt-uv-rays 2.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,636 @@
1
+ require 'mt-uv-rays'
2
+
3
+
4
+ module HttpServer
5
+ def post_init
6
+ @parser = ::HttpParser::Parser.new(self)
7
+ @state = ::HttpParser::Parser.new_instance
8
+ @state.type = :request
9
+ end
10
+
11
+ def on_message_complete(parser)
12
+ write("HTTP/1.1 200 OK\r\nSet-Cookie: Test=path\r\nSet-Cookie: other=val; path=/whatwhat\r\nContent-type: text/html\r\nContent-length: 1\r\n\r\ny")
13
+ end
14
+
15
+ def on_read(data, connection)
16
+ if @parser.parse(@state, data)
17
+ p 'parse error'
18
+ p @state.error
19
+ end
20
+ end
21
+ end
22
+
23
+ module NTLMServer
24
+ def post_init
25
+ @parser = ::HttpParser::Parser.new(self)
26
+ @state = ::HttpParser::Parser.new_instance
27
+ @state.type = :request
28
+
29
+ @req = 0
30
+ end
31
+
32
+ def on_message_complete(parser)
33
+ if @req == 0
34
+ @state = ::HttpParser::Parser.new_instance
35
+ write("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: NTLM TlRMTVNTUAACAAAAEgASADgAAAAFgokCuEPycVw6htsAAAAAAAAAAK4ArgBKAAAABgOAJQAAAA9SAEEAQgBPAE4ARQBUAE8AQwACABIAUgBBAEIATwBOAEUAVABPAEMAAQAUAFMAWQBQAFYAMQA5ADkAMAA1ADUABAAcAG8AYwAuAHIAYQBiAG8AbgBlAHQALgBjAG8AbQADADIAUwBZAFAAVgAxADkAOQAwADUANQAuAG8AYwAuAHIAYQBiAG8AbgBlAHQALgBjAG8AbQAFABYAcgBhAGIAbwBuAGUAdAAuAGMAbwBtAAcACACcZNzCwkbRAQAAAAA=\r\nContent-type: text/html\r\nContent-length: 0\r\n\r\n")
36
+ else
37
+ write("HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-length: 1\r\n\r\ny")
38
+ end
39
+ @req += 1
40
+ end
41
+
42
+ def on_read(data, connection)
43
+ if @parser.parse(@state, data)
44
+ p 'parse error'
45
+ p @state.error
46
+ end
47
+ end
48
+ end
49
+
50
+ module DigestServer
51
+ def post_init
52
+ @parser = ::HttpParser::Parser.new(self)
53
+ @state = ::HttpParser::Parser.new_instance
54
+ @state.type = :request
55
+
56
+ @req = 0
57
+ end
58
+
59
+ def on_message_complete(parser)
60
+ if @req == 0
61
+ @state = ::HttpParser::Parser.new_instance
62
+ write("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Digest realm=\"testrealm@host.com\",qop=\"auth,auth-int\",nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\",opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"\r\nContent-type: text/html\r\nContent-length: 0\r\n\r\n")
63
+ else
64
+ write("HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-length: 1\r\n\r\nd")
65
+ end
66
+ @req += 1
67
+ end
68
+
69
+ def on_read(data, connection)
70
+ if @parser.parse(@state, data)
71
+ p 'parse error'
72
+ p @state.error
73
+ end
74
+ end
75
+ end
76
+
77
+ module OldServer
78
+ def post_init
79
+ @parser = ::HttpParser::Parser.new(self)
80
+ @state = ::HttpParser::Parser.new_instance
81
+ @state.type = :request
82
+ end
83
+
84
+ def on_message_complete(parser)
85
+ write("HTTP/1.0 200 OK\r\nContent-type: text/html\r\nContent-length: 0\r\n\r\n")
86
+ end
87
+
88
+ def on_read(data, connection)
89
+ if @parser.parse(@state, data)
90
+ p 'parse error'
91
+ p @state.error
92
+ end
93
+ end
94
+ end
95
+
96
+ module WeirdServer
97
+ def post_init
98
+ @parser = ::HttpParser::Parser.new(self)
99
+ @state = ::HttpParser::Parser.new_instance
100
+ @state.type = :request
101
+ end
102
+
103
+ def on_message_complete(parser)
104
+ write("HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\nnolength")
105
+ close_connection(:after_writing)
106
+ end
107
+
108
+ def on_read(data, connection)
109
+ if @parser.parse(@state, data)
110
+ p 'parse error'
111
+ p @state.error
112
+ end
113
+ end
114
+ end
115
+
116
+ module BrokenServer
117
+ @@req = 0
118
+
119
+ def post_init
120
+ @parser = ::HttpParser::Parser.new(self)
121
+ @state = ::HttpParser::Parser.new_instance
122
+ @state.type = :request
123
+ end
124
+
125
+ def on_message_complete(parser)
126
+ if @@req == 0
127
+ @state = ::HttpParser::Parser.new_instance
128
+ write("HTTP/1.1 401 Unauthorized\r\nContent-type: text/ht")
129
+ close_connection(:after_writing)
130
+ else
131
+ write("HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-length: 3\r\n\r\nyes")
132
+ end
133
+ @@req += 1
134
+ end
135
+
136
+ def on_read(data, connection)
137
+ if @parser.parse(@state, data)
138
+ p 'parse error'
139
+ p @state.error
140
+ end
141
+ end
142
+ end
143
+
144
+ module SlowServer
145
+ @@req = 0
146
+
147
+ def post_init
148
+ @parser = ::HttpParser::Parser.new(self)
149
+ @state = ::HttpParser::Parser.new_instance
150
+ @state.type = :request
151
+ end
152
+
153
+ def on_message_complete(parser)
154
+ if @@req == 0
155
+ @state = ::HttpParser::Parser.new_instance
156
+ write("HTTP/1.1 200 OK\r\nContent-")
157
+ else
158
+ write("HTTP/1.1 200 OK\r\nContent-type: text/html\r\nContent-length: 3\r\n\r\nokg")
159
+ end
160
+ @@req += 1
161
+ end
162
+
163
+ def on_read(data, connection)
164
+ if @parser.parse(@state, data)
165
+ p 'parse error'
166
+ p @state.error
167
+ end
168
+ end
169
+ end
170
+
171
+
172
+ describe MTUV::HttpEndpoint do
173
+ before :each do
174
+ @general_failure = []
175
+
176
+ @reactor = MTLibuv::Reactor.new
177
+ @reactor.notifier do |error, context|
178
+ begin
179
+ @general_failure << "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
180
+ rescue Exception
181
+ @general_failure << "error in logger #{e.inspect}"
182
+ end
183
+ end
184
+
185
+ @timeout = @reactor.timer do
186
+ @reactor.stop
187
+ @general_failure << "test timed out"
188
+ end
189
+ @timeout.start(10000)
190
+
191
+ @request_failure = proc { |err|
192
+ @general_failure << err
193
+ @reactor.stop
194
+ }
195
+ end
196
+
197
+ describe 'basic http request' do
198
+ it "should send a request then receive a response" do
199
+ @reactor.run { |reactor|
200
+ tcp = MTUV.start_server '127.0.0.1', 3250, HttpServer
201
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250'
202
+
203
+ request = server.get(:path => '/whatwhat')
204
+ request.then(proc { |response|
205
+ @response = response
206
+ tcp.close
207
+ @reactor.stop
208
+ }, @request_failure)
209
+ }
210
+
211
+ expect(@general_failure).to eq([])
212
+ expect(@response[:"Content-type"]).to eq('text/html')
213
+ expect(@response.http_version).to eq('1.1')
214
+ expect(@response.status).to eq(200)
215
+ expect(@response.cookies).to eq({:Test=>"path", :other=>"val"})
216
+ expect(@response.keep_alive).to eq(true)
217
+
218
+ expect(@response.body).to eq('y')
219
+ end
220
+
221
+ it "should send a request then receive a response using httpi" do
222
+ require 'httpi/adapter/mt-libuv'
223
+ HTTPI.adapter = :mtlibuv
224
+
225
+ @reactor.run { |reactor|
226
+ tcp = MTUV.start_server '127.0.0.1', 3250, HttpServer
227
+
228
+ begin
229
+ request = HTTPI::Request.new("http://127.0.0.1:3250/whatwhat")
230
+ @response = HTTPI.get(request)
231
+ rescue => e
232
+ @general_failure << e
233
+ ensure
234
+ tcp.close
235
+ @reactor.stop
236
+ end
237
+ }
238
+
239
+ expect(@general_failure).to eq([])
240
+ expect(@response.headers["Content-type"]).to eq('text/html')
241
+ expect(@response.code).to eq(200)
242
+ expect(@response.raw_body).to eq('y')
243
+ end
244
+
245
+ it 'should be garbage collected', mri_only: true do
246
+ require 'weakref'
247
+ require 'objspace'
248
+
249
+ objs = nil
250
+ obj_id = nil
251
+
252
+ @reactor.run { |reactor|
253
+ tcp = MTUV.start_server '127.0.0.1', 3250, HttpServer
254
+ block = proc {
255
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250', inactivity_timeout: 300
256
+ obj_id = server.object_id
257
+ objs = WeakRef.new(server)
258
+
259
+ request = server.get(:path => '/whatwhat')
260
+ request.catch(&@request_failure)
261
+ request.finally {
262
+ tcp.close
263
+ @timeout.stop
264
+ }
265
+
266
+ server = nil
267
+ request = nil
268
+ }
269
+
270
+ block.call
271
+
272
+ reactor.scheduler.in(800) do
273
+ GC.start
274
+ ObjectSpace.garbage_collect
275
+ end
276
+ }
277
+ ObjectSpace.garbage_collect
278
+ GC.start
279
+
280
+ expect(@general_failure).to eq([])
281
+
282
+ begin
283
+ expect(objs.weakref_alive?).to eq(nil)
284
+ rescue Exception => e
285
+ objs = ObjectSpace.each_object.select{ |o| ObjectSpace.reachable_objects_from(o).map(&:object_id).include?(obj_id) }
286
+ puts "Objects referencing HTTP class:\n#{objs.inspect}\n"
287
+ raise e
288
+ end
289
+ end
290
+
291
+ it "should return the response when no length is given and the connection is closed" do
292
+ # I've seen IoT devices do this (projector screen controllers etc)
293
+ @reactor.run { |reactor|
294
+ tcp = MTUV.start_server '127.0.0.1', 3250, WeirdServer
295
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250'
296
+
297
+ request = server.get(:path => '/')
298
+ request.then(proc { |response|
299
+ @response = response
300
+ tcp.close
301
+ @reactor.stop
302
+ }, @request_failure)
303
+ }
304
+
305
+ expect(@general_failure).to eq([])
306
+ expect(@response[:"Content-type"]).to eq('text/html')
307
+ expect(@response.http_version).to eq('1.1')
308
+ expect(@response.status).to eq(200)
309
+ expect(@response.cookies).to eq({})
310
+ expect(@response.keep_alive).to eq(true)
311
+
312
+ expect(@response.body).to eq('nolength')
313
+ end
314
+
315
+ it "should send multiple requests on the same connection" do
316
+ @reactor.run { |reactor|
317
+ tcp = MTUV.start_server '127.0.0.1', 3250, HttpServer
318
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250'
319
+
320
+ request = server.get(path: '/whatwhat', req: 1)
321
+ request.then(proc { |response|
322
+ @response = response
323
+ #@reactor.stop
324
+ }, @request_failure)
325
+
326
+ request2 = server.get(path: '/', req: 2)
327
+ request2.then(proc { |response|
328
+ @response2 = response
329
+ tcp.close
330
+ @reactor.stop
331
+ }, @request_failure)
332
+ }
333
+
334
+ expect(@general_failure).to eq([])
335
+ expect(@response[:"Content-type"]).to eq('text/html')
336
+ expect(@response.http_version).to eq('1.1')
337
+ expect(@response.status).to eq(200)
338
+ expect(@response.cookies).to eq({:Test=>"path", :other=>"val"})
339
+ expect(@response.keep_alive).to eq(true)
340
+
341
+ expect(@response2[:"Content-type"]).to eq('text/html')
342
+ expect(@response2.http_version).to eq('1.1')
343
+ expect(@response2.status).to eq(200)
344
+ expect(@response2.cookies).to eq({:Test=>"path"})
345
+ expect(@response2.keep_alive).to eq(true)
346
+ end
347
+ end
348
+
349
+ describe 'old http request' do
350
+ it "should send a request then receive a response" do
351
+ @reactor.run { |reactor|
352
+ tcp = MTUV.start_server '127.0.0.1', 3250, OldServer
353
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250'
354
+
355
+ request = server.get(:path => '/')
356
+ request.then(proc { |response|
357
+ @response = response
358
+ tcp.close
359
+ @reactor.stop
360
+ }, @request_failure)
361
+ }
362
+
363
+ expect(@general_failure).to eq([])
364
+ expect(@response[:"Content-type"]).to eq('text/html')
365
+ expect(@response.http_version).to eq('1.0')
366
+ expect(@response.status).to eq(200)
367
+ expect(@response.cookies).to eq({})
368
+ expect(@response.keep_alive).to eq(false)
369
+ end
370
+
371
+ it "should send multiple requests" do
372
+ @reactor.run { |reactor|
373
+ tcp = MTUV.start_server '127.0.0.1', 3251, OldServer
374
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3251'
375
+
376
+ request = server.get(:path => '/')
377
+ request.then(proc { |response|
378
+ @response = response
379
+ #@reactor.stop
380
+ }, @request_failure)
381
+
382
+ request2 = server.get(:path => '/')
383
+ request2.then(proc { |response|
384
+ @response2 = response
385
+ tcp.close
386
+ @reactor.stop
387
+ }, @request_failure)
388
+ }
389
+
390
+ expect(@general_failure).to eq([])
391
+ expect(@response[:"Content-type"]).to eq('text/html')
392
+ expect(@response.http_version).to eq('1.0')
393
+ expect(@response.status).to eq(200)
394
+ expect(@response.cookies).to eq({})
395
+ expect(@response.keep_alive).to eq(false)
396
+
397
+ expect(@response2[:"Content-type"]).to eq('text/html')
398
+ expect(@response2.http_version).to eq('1.0')
399
+ expect(@response2.status).to eq(200)
400
+ expect(@response2.cookies).to eq({})
401
+ expect(@response2.keep_alive).to eq(false)
402
+ end
403
+ end
404
+
405
+ describe 'Auth support' do
406
+ it "should perform NTLM auth transparently" do
407
+ @reactor.run { |reactor|
408
+ tcp = MTUV.start_server '127.0.0.1', 3252, NTLMServer
409
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3252', ntlm: {
410
+ user: 'username',
411
+ password: 'password',
412
+ domain: 'domain'
413
+ }
414
+
415
+ request = server.get(path: '/')
416
+ request.then(proc { |response|
417
+ @response = response
418
+ tcp.close
419
+ @reactor.stop
420
+ }, @request_failure)
421
+ }
422
+
423
+ expect(@general_failure).to eq([])
424
+ expect(@response[:"Content-type"]).to eq('text/html')
425
+ expect(@response.http_version).to eq('1.1')
426
+ expect(@response.status).to eq(200)
427
+ expect(@response.cookies).to eq({})
428
+ expect(@response.keep_alive).to eq(true)
429
+ expect(@response.body).to eq('y')
430
+ end
431
+
432
+ it "should perform Digest auth transparently" do
433
+ @reactor.run { |reactor|
434
+ tcp = MTUV.start_server '127.0.0.1', 3252, DigestServer
435
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3252', digest: {
436
+ user: 'Mufasa',
437
+ password: 'Circle Of Life'
438
+ }
439
+
440
+ request = server.get(path: '/dir/index.html')
441
+ request.then(proc { |response|
442
+ @response = response
443
+ tcp.close
444
+ @reactor.stop
445
+ }, @request_failure)
446
+ }
447
+
448
+ expect(@general_failure).to eq([])
449
+ expect(@response[:"Content-type"]).to eq('text/html')
450
+ expect(@response.http_version).to eq('1.1')
451
+ expect(@response.status).to eq(200)
452
+ expect(@response.cookies).to eq({})
453
+ expect(@response.keep_alive).to eq(true)
454
+ expect(@response.body).to eq('d')
455
+ end
456
+ end
457
+
458
+ describe 'cookies' do
459
+ it "should accept cookies and send them on subsequent requests" do
460
+ @reactor.run { |reactor|
461
+ tcp = MTUV.start_server '127.0.0.1', 3250, HttpServer
462
+ @server = MTUV::HttpEndpoint.new 'http://127.0.0.1:3250'
463
+
464
+ request = @server.get(:path => '/whatwhat')
465
+ expect(request.cookies_hash).to eq({})
466
+
467
+ request.then(proc { |response|
468
+ tcp.close
469
+ @reactor.stop
470
+ }, @request_failure)
471
+ }
472
+
473
+ expect(@general_failure).to eq([])
474
+ expect(@server.cookiejar.get('http://127.0.0.1:3250/whatno')).to eq(["Test=path"])
475
+ @server = nil
476
+ end
477
+ end
478
+
479
+ describe 'when things go wrong' do
480
+ it "should reconnect after connection dropped and continue sending requests" do
481
+ @reactor.run { |reactor|
482
+ tcp = MTUV.start_server '127.0.0.1', 6353, BrokenServer
483
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:6353'
484
+
485
+ @response = nil
486
+ request = server.get(:path => '/')
487
+ request.then(proc { |response|
488
+ @response = response
489
+ #@reactor.stop
490
+ }, proc { |error|
491
+ @error = error
492
+ })
493
+
494
+ request2 = server.get(:path => '/')
495
+ request2.then(proc { |response|
496
+ @response2 = response
497
+ tcp.close
498
+ @reactor.stop
499
+ }, @request_failure)
500
+ }
501
+
502
+ expect(@general_failure).to eq([])
503
+ expect(@response).to eq(nil)
504
+ expect(@error).to eq(:partial_response)
505
+
506
+ expect(@response2[:"Content-type"]).to eq('text/html')
507
+ expect(@response2.http_version).to eq('1.1')
508
+ expect(@response2.status).to eq(200)
509
+ expect(@response2.cookies).to eq({})
510
+ expect(@response2.keep_alive).to eq(true)
511
+ expect(@response2.body).to eq('yes')
512
+ end
513
+
514
+ it "should reconnect after timeout and continue sending requests" do
515
+ @reactor.run { |reactor|
516
+ tcp = MTUV.start_server '127.0.0.1', 6363, SlowServer
517
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:6363', inactivity_timeout: 500
518
+
519
+ @response = nil
520
+ request = server.get(:path => '/')
521
+ request.then(proc { |response|
522
+ @response = response
523
+ #@reactor.stop
524
+ }, proc { |error|
525
+ @error = error
526
+ })
527
+
528
+ request2 = server.get(:path => '/')
529
+ request2.then(proc { |response|
530
+ @response2 = response
531
+ tcp.close
532
+ @reactor.stop
533
+ }, @request_failure)
534
+ }
535
+
536
+ expect(@general_failure).to eq([])
537
+ expect(@response).to eq(nil)
538
+ expect(@error).to eq(:timeout)
539
+
540
+ expect(@response2[:"Content-type"]).to eq('text/html')
541
+ expect(@response2.http_version).to eq('1.1')
542
+ expect(@response2.status).to eq(200)
543
+ expect(@response2.cookies).to eq({})
544
+ expect(@response2.keep_alive).to eq(true)
545
+ expect(@response2.body).to eq('okg')
546
+ end
547
+
548
+ it "should fail if the server is not available" do
549
+ @reactor.run { |reactor|
550
+ server = MTUV::HttpEndpoint.new 'http://127.0.0.1:6666', inactivity_timeout: 500
551
+
552
+ @response = nil
553
+ @response2 = nil
554
+
555
+ request = server.get(:path => '/')
556
+ request.then(proc { |response|
557
+ @response = response
558
+ #@reactor.stop
559
+ }, proc { |error|
560
+ @error = error
561
+ })
562
+
563
+ request2 = server.get(:path => '/')
564
+ request2.then(proc { |response|
565
+ @response2 = response
566
+ @reactor.stop
567
+ }, proc { |error|
568
+ @error2 = error
569
+ @reactor.stop
570
+ })
571
+ }
572
+
573
+ expect(@general_failure).to eq([])
574
+ expect(@response).to eq(nil)
575
+ # Failure will be a MTUV error
576
+ #expect(@error).to eq(:connection_failure)
577
+
578
+ expect(@response2).to eq(nil)
579
+ expect(@error2).to eq(:connection_failure)
580
+ end
581
+ end
582
+
583
+ =begin
584
+ describe 'proxy support' do
585
+ it "should work with a HTTP proxy server" do
586
+ @reactor.run { |reactor|
587
+ server = MTUV::HttpEndpoint.new 'http://www.whatsmyip.org', {
588
+ #inactivity_timeout: 1000,
589
+ proxy: {
590
+ host: '212.47.252.49',
591
+ port: 3128
592
+ }
593
+ }
594
+
595
+ @response = nil
596
+
597
+ request = server.get(:path => '/', headers: {accept: 'text/html'})
598
+ request.then(proc { |response|
599
+ @response = response
600
+ @reactor.stop
601
+ }, proc { |error|
602
+ @error = error
603
+ })
604
+ }
605
+
606
+ expect(@general_failure).to eq([])
607
+ expect(@response.status).to eq(200)
608
+ end
609
+
610
+ it "should work with a HTTPS proxy server" do
611
+ @reactor.run { |reactor|
612
+ server = MTUV::HttpEndpoint.new 'https://www.google.com.au', {
613
+ #inactivity_timeout: 1000,
614
+ proxy: {
615
+ host: '212.47.252.49',
616
+ port: 3128
617
+ }
618
+ }
619
+
620
+ @response = nil
621
+
622
+ request = server.get(:path => '/', headers: {accept: 'text/html'})
623
+ request.then(proc { |response|
624
+ @response = response
625
+ @reactor.stop
626
+ }, proc { |error|
627
+ @error = error
628
+ })
629
+ }
630
+
631
+ expect(@general_failure).to eq([])
632
+ expect(@response.status).to eq(200)
633
+ end
634
+ end
635
+ =end
636
+ end
data/spec/ping_spec.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'mt-uv-rays'
2
+
3
+
4
+ describe MTUV::Ping do
5
+ before :each do
6
+ @reactor = MTLibuv::Reactor.default
7
+ @reactor.notifier do |error, context|
8
+ begin
9
+ @general_failure << "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n") if error.backtrace}\n"
10
+ rescue Exception
11
+ @general_failure << "error in logger #{e.inspect}"
12
+ end
13
+ end
14
+ @general_failure = []
15
+ @timeout = @reactor.timer do
16
+ @reactor.stop
17
+ @general_failure << "test timed out"
18
+ end
19
+ @timeout.start(5000)
20
+ end
21
+
22
+ after :each do
23
+ @timeout.close
24
+ end
25
+
26
+ it "should ping IPv4" do
27
+ pingger = ::MTUV::Ping.new('127.0.0.1')
28
+ result = nil
29
+
30
+ @reactor.run { |reactor|
31
+ pingger.ping
32
+ @timeout.stop
33
+ }
34
+
35
+ expect(@general_failure).to eq([])
36
+ expect(pingger.pingable).to eq(true)
37
+ expect(pingger.exception).to eq(nil)
38
+ expect(pingger.warning).to eq(nil)
39
+ expect(pingger.duration).to be > 0
40
+ end
41
+
42
+ xit "should ping IPv6", travis_skip: true do
43
+ pingger = ::MTUV::Ping.new('::1')
44
+ result = nil
45
+
46
+ @reactor.run { |reactor|
47
+ pingger.ping
48
+ @timeout.stop
49
+ }
50
+
51
+ expect(@general_failure).to eq([])
52
+ expect(pingger.pingable).to eq(true)
53
+ expect(pingger.exception).to eq(nil)
54
+ expect(pingger.warning).to eq(nil)
55
+ expect(pingger.duration).to be > 0
56
+ end
57
+
58
+ it "should ping localhost after resolving using DNS" do
59
+ pingger = ::MTUV::Ping.new('localhost')
60
+ result = nil
61
+
62
+ @reactor.run { |reactor|
63
+ pingger.ping
64
+ @timeout.stop
65
+ }
66
+
67
+ expect(@general_failure).to eq([])
68
+ expect(pingger.pingable).to eq(true)
69
+ expect(pingger.exception).to eq(nil)
70
+ expect(pingger.warning).to eq(nil)
71
+ expect(pingger.duration).to be > 0
72
+ end
73
+ end