Skip to content

Instantly share code, notes, and snippets.

@clayg
Created March 16, 2014 04:35
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 clayg/9578601 to your computer and use it in GitHub Desktop.
Save clayg/9578601 to your computer and use it in GitHub Desktop.
diff --git a/test/probe/test_object_handoff.py b/test/probe/test_object_handoff.py
index 565b2ff..6b9bc8e 100755
--- a/test/probe/test_object_handoff.py
+++ b/test/probe/test_object_handoff.py
@@ -14,16 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+
from unittest import main, TestCase
from uuid import uuid4
+import time
from swiftclient import client
-from swift.common import direct_client
+from swift.common import direct_client, utils
from swift.common.exceptions import ClientException
from swift.common.manager import Manager
from test.probe.common import kill_server, kill_servers, reset_environment, \
- start_server
+ start_server, get_server_number, get_to_final_state
class TestObjectHandoff(TestCase):
@@ -182,6 +184,51 @@ class TestObjectHandoff(TestCase):
exc = err
self.assertEquals(exc.http_status, 404)
+ def get_number_from_node(self, node):
+ return get_server_number(node['port'], self.port2server)[1]
+
+ def test_x_timestamp_collision(self):
+ # setup a container
+ container = 'container-%s' % uuid4()
+ client.put_container(self.url, self.token, container)
+ # put the object
+ obj = 'object-%s' % uuid4()
+ timestamp = utils.normalize_timestamp(time.time())
+ headers = {'x-timestamp': timestamp}
+ client.put_object(self.url, self.token, container, obj, 'VERIFY',
+ headers=headers)
+ # now the other half of nodes
+ opart, onodes = self.object_ring.get_nodes(
+ self.account, container, obj)
+ # now stop one of the primaries
+ server = Manager(['object'])
+ number = self.get_number_from_node(onodes[0])
+ server.stop(number=number)
+ # and delete it
+ try:
+ client.delete_object(self.url, self.token, container, obj,
+ headers=headers)
+ except client.ClientException as exc:
+ self.assertEquals(exc.http_status, 409)
+ # fix everyone back up
+ server.start(number=number)
+ # run replication
+ get_to_final_state()
+ # verify object deleted on all nodes
+ for node in self.object_ring._devs:
+ try:
+ direct_client.direct_get_object(
+ node, opart, self.account, container, obj)
+ except ClientException as exc:
+ self.assertEquals(exc.http_status, 404)
+ else:
+ self.fail('%s/%s/%s from %r did not 404' % (
+ self.account, container, obj, node))
+ # this unfortunately leaves the containers mixed up
+ headers, objects = client.get_container(self.url, self.token,
+ container)
+ self.assert_(obj in (o['name'] for o in objects))
+
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment