You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/27 23:23:02 UTC

[1/2] git commit: [#7103] Fixed stale project data issue from long-running imports and bulk edits

Updated Branches:
  refs/heads/master 49d4ea8b2 -> b15ef350f


[#7103] Fixed stale project data issue from long-running imports and bulk edits

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/43c4bcee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/43c4bcee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/43c4bcee

Branch: refs/heads/master
Commit: 43c4bcee7b15cff07df2fa26e2d3711584377148
Parents: 49d4ea8
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Jan 27 21:07:09 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Jan 27 21:07:09 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py            |  7 +++++--
 Allura/allura/tests/model/test_artifact.py | 26 ++++++++++++++++++++++++-
 ForgeImporters/forgeimporters/base.py      | 23 +++++++++++++++++-----
 ForgeTracker/forgetracker/tasks.py         | 13 ++++++++++++-
 4 files changed, 60 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43c4bcee/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 56c7643..fed8e02 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -65,11 +65,14 @@ class Artifact(MappedClass):
         ]
 
         def before_save(data):
-            if not getattr(artifact_orm_session._get(), 'skip_mod_date', False):
+            _session = artifact_orm_session._get()
+            skip_mod_date = getattr(_session, 'skip_mod_date', False)
+            skip_last_updated = getattr(_session, 'skip_last_updated', False)
+            if not skip_mod_date:
                 data['mod_date'] = datetime.utcnow()
             else:
                 log.debug('Not updating mod_date')
-            if c.project:
+            if c.project and not skip_last_updated:
                 c.project.last_updated = datetime.utcnow()
     type_s = 'Generic Artifact'
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43c4bcee/Allura/allura/tests/model/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index e9ac6ec..d00d935 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -24,7 +24,7 @@ import re
 from datetime import datetime
 
 from pylons import tmpl_context as c
-from nose.tools import assert_raises
+from nose.tools import assert_raises, assert_equal
 from nose import with_setup
 from mock import patch
 from ming.orm.ormsession import ThreadLocalORMSession
@@ -197,3 +197,27 @@ def test_messages_unknown_lookup():
     m.author_id = ObjectId()  # something new
     assert type(m.author()) == M.User, type(m.author())
     assert m.author() == M.User.anonymous()
+
+
+@with_setup(setUp, tearDown)
+@patch('allura.model.artifact.datetime')
+def test_last_updated(_datetime):
+    c.project.last_updated = datetime(2014, 1, 1)
+    _datetime.utcnow.return_value = datetime(2014, 1, 2)
+    WM.Page(title='TestPage1')
+    ThreadLocalORMSession.flush_all()
+    assert_equal(c.project.last_updated, datetime(2014, 1, 2))
+
+
+@with_setup(setUp, tearDown)
+@patch('allura.model.artifact.datetime')
+def test_last_updated_disabled(_datetime):
+    c.project.last_updated = datetime(2014, 1, 1)
+    _datetime.utcnow.return_value = datetime(2014, 1, 2)
+    try:
+        M.artifact_orm_session._get().skip_last_updated = True
+        WM.Page(title='TestPage1')
+        ThreadLocalORMSession.flush_all()
+        assert_equal(c.project.last_updated, datetime(2014, 1, 1))
+    finally:
+        M.artifact_orm_session._get().skip_last_updated = False

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43c4bcee/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 5fbf6e1..848cb38 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -23,6 +23,7 @@ import urllib2
 from collections import defaultdict
 import traceback
 from urlparse import urlparse
+from datetime import datetime
 try:
     from cStringIO import StringIO
 except ImportError:
@@ -117,13 +118,25 @@ def object_from_path(path):
 
 
 @task(notifications_disabled=True)
-def import_tool(importer_path, project_name=None, mount_point=None, mount_label=None, **kw):
+def import_tool(importer_path, project_name=None,
+                mount_point=None, mount_label=None, **kw):
     importer = object_from_path(importer_path)()
     with ImportErrorHandler(importer, project_name, c.project) as handler,\
-            M.session.substitute_extensions(M.artifact_orm_session, [M.session.BatchIndexer]):
-        app = importer.import_tool(
-            c.project, c.user, project_name=project_name,
-            mount_point=mount_point, mount_label=mount_label, **kw)
+            M.session.substitute_extensions(M.artifact_orm_session,
+                                            [M.session.BatchIndexer]):
+        try:
+            M.artifact_orm_session._get().skip_last_updated = True
+            app = importer.import_tool(
+                c.project, c.user, project_name=project_name,
+                mount_point=mount_point, mount_label=mount_label, **kw)
+            # manually update project's last_updated field at the end of the
+            # import instead of it being updated automatically by each artifact
+            # since long-running task can cause stale project data to be saved
+            M.Project.query.update(
+                {'_id': c.project._id},
+                {'$set': {'last_updated': datetime.utcnow()}})
+        finally:
+            M.artifact_orm_session._get().skip_last_updated = False
         M.artifact_orm_session.flush()
         M.session.BatchIndexer.flush()
         if app:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43c4bcee/ForgeTracker/forgetracker/tasks.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tasks.py b/ForgeTracker/forgetracker/tasks.py
index 6492d7d..0fdebc5 100644
--- a/ForgeTracker/forgetracker/tasks.py
+++ b/ForgeTracker/forgetracker/tasks.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import logging
+from datetime import datetime
 
 from pylons import tmpl_context as c
 
@@ -41,4 +42,14 @@ def move_tickets(ticket_ids, destination_tracker_id):
 
 @task
 def bulk_edit(**post_data):
-    c.app.globals.update_tickets(**post_data)
+    try:
+        M.artifact_orm_session._get().skip_last_updated = True
+        c.app.globals.update_tickets(**post_data)
+        # manually update project's last_updated field at the end of the
+        # import instead of it being updated automatically by each artifact
+        # since long-running task can cause stale project data to be saved
+        M.Project.query.update(
+            {'_id': c.project._id},
+            {'$set': {'last_updated': datetime.utcnow()}})
+    finally:
+        M.artifact_orm_session._get().skip_last_updated = False


[2/2] git commit: [#7103] Fixed test failure

Posted by tv...@apache.org.
[#7103] Fixed test failure

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b15ef350
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b15ef350
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b15ef350

Branch: refs/heads/master
Commit: b15ef350f92e908556fc4fd15b265b266e5db444
Parents: 43c4bce
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Jan 27 22:08:14 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Jan 27 22:08:14 2014 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/tests/test_base.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b15ef350/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index c5aeb68..e93a6b1 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -45,10 +45,12 @@ class TestProjectExtractor(TestCase):
         self.assertEqual(r, urlopen.return_value)
 
 
+@mock.patch.object(base, 'datetime')
+@mock.patch.object(base, 'M')
 @mock.patch.object(base, 'object_from_path')
 @mock.patch.object(base, 'c')
 @mock.patch.object(base, 'g')
-def test_import_tool(g, c, object_from_path):
+def test_import_tool(g, c, object_from_path, M, _datetime):
     c.project = mock.Mock(name='project')
     c.user = mock.Mock(name='user')
     object_from_path.return_value = importer = mock.Mock()
@@ -58,11 +60,16 @@ def test_import_tool(g, c, object_from_path):
         'forgeimporters.base.ToolImporter', project_name='project_name',
         mount_point='mount_point', mount_label='mount_label')
     app = importer.return_value.import_tool.return_value
-    importer.return_value.import_tool.assert_called_once_with(c.project,
-                                                              c.user, project_name='project_name', mount_point='mount_point',
-                                                              mount_label='mount_label')
-    g.director.create_activity.assert_called_once_with(c.user, "imported",
-                                                       app.config, related_nodes=[c.project])
+    importer.return_value.import_tool.assert_called_once_with(
+        c.project,
+        c.user, project_name='project_name', mount_point='mount_point',
+        mount_label='mount_label')
+    M.Project.query.update.assert_called_once_with(
+        {'_id': c.project._id},
+        {'$set': {'last_updated': _datetime.utcnow()}})
+    g.director.create_activity.assert_called_once_with(
+        c.user, "imported",
+        app.config, related_nodes=[c.project])
     g.post_event.assert_called_once_with(
         'import_tool_task_succeeded',
         'source',