falls_back_on 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/falls_back_on/definition.rb +1 -0
- data/lib/falls_back_on/version.rb +1 -1
- data/test/helper.rb +3 -3
- data/test/test_falls_back_on.rb +21 -0
- metadata +3 -3
data/test/helper.rb
CHANGED
@@ -20,12 +20,12 @@ rescue ArgumentError
|
|
20
20
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
21
21
|
end
|
22
22
|
|
23
|
-
my_client = Memcached.new
|
24
|
-
CacheMethod.config.storage = my_client
|
25
|
-
LockMethod.config.storage = my_client
|
23
|
+
$my_client = Memcached.new
|
26
24
|
|
27
25
|
class Test::Unit::TestCase
|
28
26
|
def setup
|
27
|
+
CacheMethod.config.storage = $my_client
|
28
|
+
LockMethod.config.storage = $my_client
|
29
29
|
CacheMethod.config.storage.flush
|
30
30
|
LockMethod.config.storage.flush
|
31
31
|
@old_abort_on_exception = Thread.abort_on_exception
|
data/test/test_falls_back_on.rb
CHANGED
@@ -38,6 +38,13 @@ class Car3
|
|
38
38
|
falls_back_on :long_running_calculation => lambda { sleep 3 }
|
39
39
|
end
|
40
40
|
|
41
|
+
class Car4
|
42
|
+
attr_accessor :fuel
|
43
|
+
def ==(other)
|
44
|
+
self.fuel == other.fuel
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
41
48
|
class TestFallsBackOn < Test::Unit::TestCase
|
42
49
|
def test_fallback
|
43
50
|
assert_equal 'gasoline', Car1.fallback.fuel
|
@@ -96,6 +103,10 @@ class TestFallsBackOn < Test::Unit::TestCase
|
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
106
|
+
# 3 seconds every time.
|
107
|
+
# start it, wait a second, clear fallbacks (and therefore any locks)
|
108
|
+
# you would expect it to completely restart, taking another 3 seconds
|
109
|
+
# so it will time out after 4 seconds
|
99
110
|
assert_raises(Timeout::Error) do
|
100
111
|
Timeout.timeout(4) do
|
101
112
|
blocker = Thread.new { Car3.fallback.long_running_calculation }
|
@@ -105,4 +116,14 @@ class TestFallsBackOn < Test::Unit::TestCase
|
|
105
116
|
end
|
106
117
|
end
|
107
118
|
end
|
119
|
+
|
120
|
+
def test_no_memcached
|
121
|
+
CacheMethod.config.storage = nil
|
122
|
+
LockMethod.config.storage = nil
|
123
|
+
assert_equal 5.5, Car2.fallback.efficiency
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_no_definition
|
127
|
+
assert_equal Car4.new, Car4.fallback
|
128
|
+
end
|
108
129
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: falls_back_on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|