net-http-persistent 1.3.1 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.4 / 2010-09-29
2
+
3
+ * Minor Enhancements
4
+ * Added the very dangerous #shutdown_in_all_threads. IT IS DANGEROUS!.
5
+ Patch by Torsten Schönebaum.
6
+
1
7
  === 1.3.1 / 2010-09-13
2
8
 
3
9
  * Bug Fixes
@@ -37,7 +37,7 @@ class Net::HTTP::Persistent
37
37
  ##
38
38
  # The version of Net::HTTP::Persistent use are using
39
39
 
40
- VERSION = '1.3.1'
40
+ VERSION = '1.4'
41
41
 
42
42
  ##
43
43
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -388,13 +388,20 @@ class Net::HTTP::Persistent
388
388
  end
389
389
 
390
390
  ##
391
- # Shuts down all connections in this thread.
391
+ # Shuts down all connections for +thread+.
392
+ #
393
+ # Uses the current thread by default.
392
394
  #
393
- # If you've used Net::HTTP::Persistent across multiple threads you must call
394
- # this in each thread.
395
+ # If you've used Net::HTTP::Persistent across multiple threads you should
396
+ # call this in each thread when you're done making HTTP requests.
397
+ #
398
+ # *NOTE*: Calling shutdown for another thread can be dangerous!
399
+ #
400
+ # If the thread is still using the connection it may cause an error! It is
401
+ # best to call #shutdown in the thread at the appropriate time instead!
395
402
 
396
- def shutdown
397
- connections = Thread.current[@connection_key]
403
+ def shutdown thread = Thread.current
404
+ connections = thread[@connection_key]
398
405
 
399
406
  connections.each do |_, connection|
400
407
  begin
@@ -403,8 +410,26 @@ class Net::HTTP::Persistent
403
410
  end
404
411
  end if connections
405
412
 
406
- Thread.current[@connection_key] = nil
407
- Thread.current[@request_key] = nil
413
+ thread[@connection_key] = nil
414
+ thread[@request_key] = nil
415
+ end
416
+
417
+ ##
418
+ # Shuts down all connections in all threads
419
+ #
420
+ # *NOTE*: THIS METHOD IS VERY DANGEROUS!
421
+ #
422
+ # Do not call this method if other threads are still using their
423
+ # connections! Call #shutdown at the appropriate time instead!
424
+ #
425
+ # Use this method only as a last resort!
426
+
427
+ def shutdown_in_all_threads
428
+ Thread.list.each do |thread|
429
+ shutdown thread
430
+ end
431
+
432
+ nil
408
433
  end
409
434
 
410
435
  ##
@@ -575,6 +575,58 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
575
575
  assert_nil Thread.current[@http.request_key]
576
576
  end
577
577
 
578
+ def test_shutdown_thread
579
+ t = Thread.new do
580
+ c = connection
581
+ conns
582
+ reqs
583
+
584
+ Thread.stop
585
+
586
+ c
587
+ end
588
+
589
+ Thread.pass until t.status == 'sleep'
590
+
591
+ c = connection
592
+
593
+ @http.shutdown t
594
+
595
+ refute c.finished?
596
+
597
+ t.run
598
+ assert t.value.finished?
599
+ assert_nil t[@http.connection_key]
600
+ assert_nil t[@http.request_key]
601
+ end
602
+
603
+ def test_shutdown_in_all_threads
604
+ t = Thread.new do
605
+ c = connection
606
+ conns
607
+ reqs
608
+
609
+ Thread.stop
610
+
611
+ c
612
+ end
613
+
614
+ Thread.pass until t.status == 'sleep'
615
+
616
+ c = connection
617
+
618
+ assert_nil @http.shutdown_in_all_threads
619
+
620
+ assert c.finished?
621
+ assert_nil Thread.current[@http.connection_key]
622
+ assert_nil Thread.current[@http.request_key]
623
+
624
+ t.run
625
+ assert t.value.finished?
626
+ assert_nil t[@http.connection_key]
627
+ assert_nil t[@http.request_key]
628
+ end
629
+
578
630
  def test_ssl
579
631
  @http.verify_callback = :callback
580
632
  c = Net::HTTP.new 'localhost', 80
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 1
10
- version: 1.3.1
8
+ - 4
9
+ version: "1.4"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Eric Hodel
@@ -36,7 +35,7 @@ cert_chain:
36
35
  x52qPcexcYZR7w==
37
36
  -----END CERTIFICATE-----
38
37
 
39
- date: 2010-09-13 00:00:00 -07:00
38
+ date: 2010-09-30 00:00:00 -07:00
40
39
  default_executable:
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file