Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C0CD917C6A for ; Thu, 23 Oct 2014 17:59:47 +0000 (UTC) Received: (qmail 8096 invoked by uid 500); 23 Oct 2014 17:59:47 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 8049 invoked by uid 500); 23 Oct 2014 17:59:47 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 8000 invoked by uid 99); 23 Oct 2014 17:59:47 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Oct 2014 17:59:47 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4DA2216FCD; Thu, 23 Oct 2014 17:59:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: commits@allura.apache.org Date: Thu, 23 Oct 2014 17:59:47 -0000 Message-Id: <55f1fa0dbe7b4a9291e8ce4621b9473d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: [#7647] ticket:669 Add test to reproduce race condition in artifact versioning Repository: allura Updated Branches: refs/heads/master 7ba07dc28 -> bb7c86e90 [#7647] ticket:669 Add test to reproduce race condition in artifact versioning Project: http://git-wip-us.apache.org/repos/asf/allura/repo Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1e15eeeb Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1e15eeeb Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1e15eeeb Branch: refs/heads/master Commit: 1e15eeeb79dbba2920df4f3f1631ca1352a51a39 Parents: 7ba07dc Author: Igor Bondarenko Authored: Fri Oct 17 16:05:18 2014 +0300 Committer: Dave Brondsema Committed: Thu Oct 23 13:59:29 2014 -0400 ---------------------------------------------------------------------- ForgeWiki/forgewiki/tests/test_models.py | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/allura/blob/1e15eeeb/ForgeWiki/forgewiki/tests/test_models.py ---------------------------------------------------------------------- diff --git a/ForgeWiki/forgewiki/tests/test_models.py b/ForgeWiki/forgewiki/tests/test_models.py new file mode 100644 index 0000000..619f5dd --- /dev/null +++ b/ForgeWiki/forgewiki/tests/test_models.py @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from allura.tests import TestController +from allura.tests import decorators as td +from alluratest.controller import setup_global_objects + +from forgewiki.model import Page + + +class TestPageSnapshots(TestController): + + # Note: test name starts with '_' makes nose don't pick it up automatically. + # This is done intentionally to avoid run this test on every commit. + # You can run it manually like this: + # nosetests forgewiki.tests.test_models:TestPageSnapshots._test_version_race + # You should check that threads does not throw `DuplicateKeyError`. + # It's hard to reproduce this mannually + @td.with_wiki + def _test_version_race(self): + import time + import random + from threading import Thread + + page = Page.upsert('test-page') + page.commit() + + def run(n): + setup_global_objects() + for i in range(10): + page = Page.query.get(title='test-page') + page.text = 'Test Page %s.%s' % (n, i) + time.sleep(random.random()) + page.commit() + + t1 = Thread(target=lambda: run(1)) + t2 = Thread(target=lambda: run(2)) + t1.start() + t2.start() + t1.join() + t2.join() + + page = Page.query.get(title='test-page') + # 10 changes by each thread + initial upsert + assert page.history().count() == 21, page.history().count()