From 74c4689691cd9d78d93c4c0f13befdbf5ce7a87e Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Sat, 9 Jul 2011 20:47:49 -0400 Subject: [PATCH 1/2] Move the timeout to Mock and stop hardcoding. --- lib/fog/core/mock.rb | 10 ++++++++++ lib/fog/core/model.rb | 2 +- lib/fog/core/wait_for.rb | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/fog/core/mock.rb b/lib/fog/core/mock.rb index 6847d56b5..9b19d0eb9 100644 --- a/lib/fog/core/mock.rb +++ b/lib/fog/core/mock.rb @@ -21,6 +21,16 @@ module Fog @delay end + @timeout = 600 + def self.timeout + @timeout + end + + def self.timeout=(new_timeout) + raise ArgumentError, "timeout must be non-negative" unless new_timeout >= 0 + @timeout = new_timeout + end + def self.delay=(new_delay) raise ArgumentError, "delay must be non-negative" unless new_delay >= 0 @delay = new_delay diff --git a/lib/fog/core/model.rb b/lib/fog/core/model.rb index 307472042..6143d90fa 100644 --- a/lib/fog/core/model.rb +++ b/lib/fog/core/model.rb @@ -42,7 +42,7 @@ module Fog attributes.to_json end - def wait_for(timeout=600, interval=1, &block) + def wait_for(timeout=Fog::Mock.timeout, interval=1, &block) reload retries = 3 Fog.wait_for(timeout, interval) do diff --git a/lib/fog/core/wait_for.rb b/lib/fog/core/wait_for.rb index 3a9133b32..685298c75 100644 --- a/lib/fog/core/wait_for.rb +++ b/lib/fog/core/wait_for.rb @@ -1,6 +1,6 @@ module Fog - def self.wait_for(timeout=600, interval=1, &block) + def self.wait_for(timeout=Fog::Mock.timeout, interval=1, &block) duration = 0 start = Time.now until yield || duration > timeout @@ -14,4 +14,4 @@ module Fog end end -end \ No newline at end of file +end From 49d8a92a639844420ef76235d76c8923ffe2edab Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Mon, 11 Jul 2011 18:06:47 -0400 Subject: [PATCH 2/2] Move timeout up to Fog from Fog::Mock. --- lib/fog/core.rb | 1 + lib/fog/core/mock.rb | 10 ---------- lib/fog/core/model.rb | 2 +- lib/fog/core/timeout.rb | 13 +++++++++++++ lib/fog/core/wait_for.rb | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 lib/fog/core/timeout.rb diff --git a/lib/fog/core.rb b/lib/fog/core.rb index 2c5fe2e06..6e1fa00e6 100644 --- a/lib/fog/core.rb +++ b/lib/fog/core.rb @@ -31,4 +31,5 @@ require 'fog/core/service' require 'fog/core/ssh' require 'fog/core/scp' require 'fog/core/time' +require 'fog/core/timeout' require 'fog/core/wait_for' diff --git a/lib/fog/core/mock.rb b/lib/fog/core/mock.rb index 9b19d0eb9..6847d56b5 100644 --- a/lib/fog/core/mock.rb +++ b/lib/fog/core/mock.rb @@ -21,16 +21,6 @@ module Fog @delay end - @timeout = 600 - def self.timeout - @timeout - end - - def self.timeout=(new_timeout) - raise ArgumentError, "timeout must be non-negative" unless new_timeout >= 0 - @timeout = new_timeout - end - def self.delay=(new_delay) raise ArgumentError, "delay must be non-negative" unless new_delay >= 0 @delay = new_delay diff --git a/lib/fog/core/model.rb b/lib/fog/core/model.rb index 6143d90fa..372cf3498 100644 --- a/lib/fog/core/model.rb +++ b/lib/fog/core/model.rb @@ -42,7 +42,7 @@ module Fog attributes.to_json end - def wait_for(timeout=Fog::Mock.timeout, interval=1, &block) + def wait_for(timeout=Fog.timeout, interval=1, &block) reload retries = 3 Fog.wait_for(timeout, interval) do diff --git a/lib/fog/core/timeout.rb b/lib/fog/core/timeout.rb new file mode 100644 index 000000000..705d1f3f2 --- /dev/null +++ b/lib/fog/core/timeout.rb @@ -0,0 +1,13 @@ +module Fog + + @timeout = 600 + def self.timeout + @timeout + end + + def self.timeout=(new_timeout) + raise ArgumentError, "timeout must be non-negative" unless new_timeout >= 0 + @timeout = new_timeout + end + +end diff --git a/lib/fog/core/wait_for.rb b/lib/fog/core/wait_for.rb index 685298c75..6bf337c81 100644 --- a/lib/fog/core/wait_for.rb +++ b/lib/fog/core/wait_for.rb @@ -1,6 +1,6 @@ module Fog - def self.wait_for(timeout=Fog::Mock.timeout, interval=1, &block) + def self.wait_for(timeout=Fog.timeout, interval=1, &block) duration = 0 start = Time.now until yield || duration > timeout