1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# frozen_string_literal: true
require "helper"
class TestDistributedTransactions < Minitest::Test
include Helper::Distributed
def test_multi_discard_without_watch
@foo = nil
assert_raises Redis::Distributed::CannotDistribute do
r.multi { @foo = 1 }
end
assert_nil @foo
assert_raises Redis::Distributed::CannotDistribute do
r.discard
end
end
def test_watch_unwatch_without_clustering
assert_raises Redis::Distributed::CannotDistribute do
r.watch("foo", "bar")
end
r.watch("{qux}foo", "{qux}bar") do
assert_raises Redis::Distributed::CannotDistribute do
r.get("{baz}foo")
end
r.unwatch
end
assert_raises Redis::Distributed::CannotDistribute do
r.unwatch
end
end
def test_watch_with_exception
assert_raises StandardError do
r.watch("{qux}foo", "{qux}bar") do
raise StandardError, "woops"
end
end
assert_equal "OK", r.set("{other}baz", 1)
end
def test_watch_unwatch
assert_equal "OK", r.watch("{qux}foo", "{qux}bar")
assert_equal "OK", r.unwatch
end
def test_watch_multi_with_block
r.set("{qux}baz", 1)
r.watch("{qux}foo", "{qux}bar", "{qux}baz") do
assert_equal '1', r.get("{qux}baz")
result = r.multi do |transaction|
transaction.incrby("{qux}foo", 3)
transaction.incrby("{qux}bar", 6)
transaction.incrby("{qux}baz", 9)
end
assert_equal [3, 6, 10], result
end
end
end
|