From 53cbe145564ad04eff4db234855f9e3cd942669e Mon Sep 17 00:00:00 2001 From: nick Date: Wed, 30 Oct 2013 22:45:12 +0000 Subject: [PATCH] mirror: lengthen the request timeout to 60 seconds This is complicated slightly by a need to keep the tests fast, so we introduce an environment variable that can override the constant --- src/mirror.c | 17 ++++++++++++++++- src/mirror.h | 7 +++++-- tests/acceptance/fakes/dest/hang_after_write.rb | 8 +++++++- tests/acceptance/test_source_error_handling.rb | 4 ++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/mirror.c b/src/mirror.c index d9d868e..a53b83c 100644 --- a/src/mirror.c +++ b/src/mirror.c @@ -762,7 +762,22 @@ void mirror_run( struct server *serve ) ctrl.write_watcher.data = (void*) &ctrl; ev_init( &ctrl.timeout_watcher, mirror_timeout_cb ); - ctrl.timeout_watcher.repeat = MS_REQUEST_LIMIT_SECS_F ; + + char * env_request_limit = getenv( "FLEXNBD_MS_REQUEST_LIMIT_SECS" ); + double timeout_limit = MS_REQUEST_LIMIT_SECS_F; + + if ( NULL != env_request_limit ) { + char *endptr = NULL; + errno = 0; + double limit = strtod( env_request_limit, &endptr ); + warn( SHOW_ERRNO( "Got %f from strtod", limit ) ); + + if ( errno == 0 ) { + timeout_limit = limit; + } + } + + ctrl.timeout_watcher.repeat = timeout_limit; ev_init( &ctrl.limit_watcher, mirror_limit_cb ); ctrl.limit_watcher.repeat = 1.0; // We check bps every second. seems sane. diff --git a/src/mirror.h b/src/mirror.h index 91c8be1..d390fdf 100644 --- a/src/mirror.h +++ b/src/mirror.h @@ -50,9 +50,12 @@ enum mirror_state; * request, this is the time between the end of the NBD request and the * start of the NBD reply. For a write request, this is the time * between the end of the written data and the start of the NBD reply. + * Can be overridden by the environment variable: + * FLEXNBD_MS_REQUEST_LIMIT_SECS */ -#define MS_REQUEST_LIMIT_SECS 4 -#define MS_REQUEST_LIMIT_SECS_F 4.0 + +#define MS_REQUEST_LIMIT_SECS 60 +#define MS_REQUEST_LIMIT_SECS_F 60.0 enum mirror_finish_action { ACTION_EXIT, diff --git a/tests/acceptance/fakes/dest/hang_after_write.rb b/tests/acceptance/fakes/dest/hang_after_write.rb index f5e796a..affda53 100755 --- a/tests/acceptance/fakes/dest/hang_after_write.rb +++ b/tests/acceptance/fakes/dest/hang_after_write.rb @@ -20,7 +20,13 @@ t = Thread.start do client2.close end -sleep( FlexNBD::MS_REQUEST_LIMIT_SECS + 2 ) +sleep_time = if ENV.has_key?('FLEXNBD_MS_REQUEST_LIMIT_SECS') + ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'].to_f +else + FlexNBD::MS_REQUEST_LIMIT_SECS +end + +sleep( sleep_time + 2.0 ) client1.close t.join diff --git a/tests/acceptance/test_source_error_handling.rb b/tests/acceptance/test_source_error_handling.rb index 9dd3f60..7a233ad 100644 --- a/tests/acceptance/test_source_error_handling.rb +++ b/tests/acceptance/test_source_error_handling.rb @@ -7,6 +7,9 @@ require 'environment' class TestSourceErrorHandling < Test::Unit::TestCase def setup + @old_env = ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'] + ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'] = "4.0" + @env = Environment.new @env.writefile1( "f" * 4 ) @env.serve1 @@ -16,6 +19,7 @@ class TestSourceErrorHandling < Test::Unit::TestCase def teardown @env.nbd1.can_die(0) @env.cleanup + ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'] = @old_env end