Skip to content

Instantly share code, notes, and snippets.

@bloodeagle40234
Last active April 7, 2017 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bloodeagle40234/34cc09f70b299f97ef4f8b684d6e9bc7 to your computer and use it in GitHub Desktop.
Save bloodeagle40234/34cc09f70b299f97ef4f8b684d6e9bc7 to your computer and use it in GitHub Desktop.
======================================================================
FAIL: test_replicate_object_with_exception (test.unit.common.test_db_replicator.TestDBReplicator)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/stack/swift/test/unit/common/test_db_replicator.py", line 679, in test_replicate_object_with_exception
do_test(replicator.ring.devs[3]['id'], 1, [1, 2, 3, 5])
File "/opt/stack/swift/test/unit/common/test_db_replicator.py", line 674, in do_test
self.assertEqual(expected_to_repl, called_devices)
AssertionError: Lists differ: [1, 2, 3, 5] != [1, 2, 3, 4]
First differing element 3:
5
4
- [1, 2, 3, 5]
? ^
+ [1, 2, 3, 4]
? ^
"""Fail immediately, with the given message."""
>> raise self.failureException('Lists differ: [1, 2, 3, 5] != [1, 2, 3, 4]\n\nFirst differing element 3:\n5\n4\n\n- [1, 2, 3, 5]\n? ^\n\n+ [1, 2, 3, 4]\n? ^\n')
----------------------------------------------------------------------
Ran 64 tests in 0.553s
FAILED (failures=1)
diff --git a/test/unit/common/test_db_replicator.py b/test/unit/common/test_db_replicator.py
index a1a18fe..9949279 100644
--- a/test/unit/common/test_db_replicator.py
+++ b/test/unit/common/test_db_replicator.py
@@ -648,27 +648,41 @@ class TestDBReplicator(unittest.TestCase):
replicator.ring = FakeRingWithNodes().Ring('path')
replicator.brokerclass = FakeAccountBroker
replicator.delete_db = self.stub_delete_db
+
replicator._repl_to_node = mock.Mock(side_effect=Exception())
replicator._replicate_object('0', '/path/to/file',
replicator.ring.devs[0]['id'])
self.assertEqual(2, replicator._repl_to_node.call_count)
+
+ def do_test(local_node, fail_count, expected_to_repl):
+ called_devices = []
+ fail_counter = [fail_count]
+
+ def fake_repl_to_node(
+ node, broker, partition, info, different_region):
+ called_devices.append(node['id'])
+ if fail_counter[0]:
+ fail_counter[0] -= 1
+ raise DriveNotMounted()
+ else:
+ return True
+
+ with mock.patch.object(
+ replicator, '_repl_to_node', fake_repl_to_node):
+ replicator._replicate_object('0', '/path/to/file', local_node)
+
+ self.assertEqual(expected_to_repl, called_devices)
+
# with one DriveNotMounted exception called on +1 more replica
- replicator._repl_to_node = mock.Mock(side_effect=[DriveNotMounted()])
- replicator._replicate_object('0', '/path/to/file',
- replicator.ring.devs[0]['id'])
- self.assertEqual(3, replicator._repl_to_node.call_count)
+ do_test(replicator.ring.devs[0]['id'], 1, [2, 3, 4])
# called on +1 more replica when *first* handoff and self
- replicator._repl_to_node = mock.Mock(side_effect=[DriveNotMounted()])
- replicator._replicate_object('0', '/path/to/file',
- replicator.ring.devs[3]['id'])
- self.assertEqual(4, replicator._repl_to_node.call_count)
+ do_test(replicator.ring.devs[3]['id'], 1, [1, 2, 3, 5])
+ # even if it's the last handoff it works to keep 3 replicas
+ # 2 primaries + 1 handoff
+ do_test(replicator.ring.devs[-1]['id'], 1, [1, 2, 3, 4])
# with two DriveNotMounted exceptions called on +2 more replica keeping
# durability
- replicator._repl_to_node = mock.Mock(
- side_effect=[DriveNotMounted()] * 2)
- replicator._replicate_object('0', '/path/to/file',
- replicator.ring.devs[0]['id'])
- self.assertEqual(4, replicator._repl_to_node.call_count)
+ do_test(replicator.ring.devs[0]['id'], 2, [2, 3, 4, 5])
def test_replicate_object_with_exception_run_out_of_nodes(self):
replicator = TestReplicator({})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment