Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move timeout tests to timeout_spec, which runs very very very slow :-(

  • Loading branch information...
commit 9e22a0603c524dbdd829536a60563f213971fe99 1 parent 6f87c3e
@flyerhzm flyerhzm authored
View
43 spec/memcached_spec.rb
@@ -227,48 +227,5 @@
end
end
end
-
- context "timeout" do
- before(:all) do
- @memcached = Memcached.new("127.0.0.1:11211")
- @timeout_memcached = Memcached.new("127.0.0.1:11211", :timeout => 1, :exception_retry_limit => 0)
- end
- after(:all) do
- @timeout_memcached.quit
- @memcached.quit
- end
-
- it "should set timeout" do
- lambda { @timeout_memcached.set "key", "new_value" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should add timeout" do
- @memcached.delete "key" rescue nil
- lambda { @timeout_memcached.add "key", "new_value" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should replace timeout" do
- @memcached.set "key", "value"
- lambda { @timeout_memcached.replace "key", "new_value" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should delete timeout" do
- @memcached.set "key", "value"
- lambda { @timeout_memcached.delete "key" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should get timeout" do
- @memcached.set "key", "value"
- lambda { @timeout_memcached.get "key" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should increment timeout" do
- lambda { @timeout_memcached.increment "intkey" }.should raise_error(Memcached::ATimeoutOccurred)
- end
-
- it "should decrement timeout" do
- lambda { @timeout_memcached.decrement "intkey" }.should raise_error(Memcached::ATimeoutOccurred)
- end
- end
end
end
View
86 spec/timeout_spec.rb
@@ -0,0 +1,86 @@
+require 'spec_helper'
+
+# This is a stupid way to test timeout cases.
+#
+# Originally, I want to mock MemcachedClient methods to throw OperationTimeout, like
+#
+# MemcachedClient.any_instance.stubs(:get).raises(OperationTimeout)
+# lambda { @timeout_memcached.get "key" }.should raise_error(Memcached::ATimeoutOccurred)
+#
+# But it doesn't work.
+#
+# The current solution is to call @timeout_memcahced.get in an infinite loop until a
+# Memcached::ATimeoutOccurred raised. It works, but really slow down the tests, I hate it.
+#
+# If you have a better solution, please let me know flyerhzm at gmail dot com, thanks.
+describe Memcached do
+ before(:all) do
+ @memcached = Memcached.new("127.0.0.1:11211")
+ @timeout_memcached = Memcached.new("127.0.0.1:11211", :timeout => 1, :exception_retry_limit => 0)
+ end
+
+ after(:all) do
+ @timeout_memcached.quit
+ @memcached.quit
+ end
+
+ it "should set timeout" do
+ lambda {
+ while true
+ @timeout_memcached.set "key", "new_value"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should add timeout" do
+ lambda {
+ while true
+ @memcached.delete "key" rescue nil
+ @timeout_memcached.add "key", "new_value"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should replace timeout" do
+ @memcached.set "key", "value"
+ lambda {
+ while true
+ @timeout_memcached.replace "key", "new_value"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should delete timeout" do
+ lambda {
+ while true
+ @memcached.set "key", "value"
+ @timeout_memcached.delete "key"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should get timeout" do
+ @memcached.set "key", "value"
+ lambda {
+ while true
+ @timeout_memcached.get "key"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should increment timeout" do
+ lambda {
+ while true
+ @timeout_memcached.increment "intkey"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should decrement timeout" do
+ lambda {
+ while true
+ @timeout_memcached.decrement "intkey"
+ end
+ }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+end
View
BIN  target/spymemcached-ext-0.0.1.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.