Commit 8b7a552 1 parent 023e0c1 commit 8b7a552 Copy full SHA for 8b7a552
File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -76,9 +76,16 @@ def raw_semian_options
76
76
@raw_semian_options ||= begin
77
77
@raw_semian_options = Semian ::NetHTTP . retrieve_semian_configuration ( address , port )
78
78
@raw_semian_options = @raw_semian_options . dup unless @raw_semian_options . nil?
79
+ calculate_error_timeout if @raw_semian_options [ :capacity ] && !@raw_semian_options [ :error_timeout ]
79
80
end
80
81
end
81
82
83
+ def calculate_error_timeout
84
+ capacity = @raw_semian_options [ :capacity ]
85
+ error_timeout = ( read_timeout * capacity ) / ( 1 - capacity )
86
+ @raw_semian_options . merge! ( { error_timeout : error_timeout } )
87
+ end
88
+
82
89
def resource_exceptions
83
90
Semian ::NetHTTP . exceptions
84
91
end
Original file line number Diff line number Diff line change @@ -353,6 +353,29 @@ def test_persistent_state_after_server_restart
353
353
end
354
354
end
355
355
356
+ def test_capacity_option_calculates_the_error_timeout_based_upon_read_timeout
357
+ options_with_capacity = DEFAULT_SEMIAN_OPTIONS . dup . merge! ( { capacity : 0.75 } )
358
+ options_with_capacity . delete ( :error_timeout )
359
+ semian_configuration_proc = proc do |host , port |
360
+ options_with_capacity
361
+ end
362
+ with_semian_configuration ( semian_configuration_proc ) do
363
+ http = Net ::HTTP . new ( HOSTNAME , TOXIC_PORT )
364
+ assert_equal 180 , http . raw_semian_options [ :error_timeout ]
365
+ end
366
+ end
367
+
368
+ def test_capacity_option_defaults_to_error_timeout_when_both_are_provided
369
+ options_with_capacity = DEFAULT_SEMIAN_OPTIONS . dup . merge! ( { capacity : 0.75 } )
370
+ semian_configuration_proc = proc do |host , port |
371
+ options_with_capacity
372
+ end
373
+ with_semian_configuration ( semian_configuration_proc ) do
374
+ http = Net ::HTTP . new ( HOSTNAME , TOXIC_PORT )
375
+ assert_equal 10 , http . raw_semian_options [ :error_timeout ]
376
+ end
377
+ end
378
+
356
379
private
357
380
358
381
def with_semian_configuration ( options = DEFAULT_SEMIAN_CONFIGURATION )
You can’t perform that action at this time.
0 commit comments