/
replication_ack_test.rb
72 lines (56 loc) · 2.04 KB
/
replication_ack_test.rb
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
71
72
require 'test_helper'
class ReplicaSetAckTest < Test::Unit::TestCase
def setup
ensure_cluster(:rs)
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
@slave1 = MongoClient.new(
@client.secondary_pools[0].host,
@client.secondary_pools[0].port, :slave_ok => true)
assert !@slave1.read_primary?
@db = @client.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@col = @db.collection("test-sets")
end
def teardown
@client.close if @conn
end
def self.shutdown
@@cluster.stop
@@cluster.clobber
end
def test_safe_mode_with_w_failure
assert_raise_error OperationFailure, "timeout" do
@col.insert({:foo => 1}, :w => 4, :wtimeout => 1, :fsync => true)
end
assert_raise_error OperationFailure, "timeout" do
@col.update({:foo => 1}, {:foo => 2}, :w => 4, :wtimeout => 1, :fsync => true)
end
assert_raise_error OperationFailure, "timeout" do
@col.remove({:foo => 2}, :w => 4, :wtimeout => 1, :fsync => true)
end
end
def test_safe_mode_replication_ack
@col.insert({:baz => "bar"}, :w => 3, :wtimeout => 5000)
assert @col.insert({:foo => "0" * 5000}, :w => 3, :wtimeout => 5000)
assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count
assert @col.update({:baz => "bar"}, {:baz => "foo"}, :w => 3, :wtimeout => 5000)
assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
assert @col.remove({}, :w => 3, :wtimeout => 5000)
assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count
end
def test_last_error_responses
20.times { @col.insert({:baz => "bar"}) }
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
assert response['ok'] == 1
assert response['lastOp']
@col.update({}, {:baz => "foo"})
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
assert response['ok'] == 1
assert response['lastOp']
@col.remove({})
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
assert response['ok'] == 1
assert response['n'] == 20
assert response['lastOp']
end
end