You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2012/10/16 16:27:08 UTC
[9/16] git commit: [#4927] ticket:185 put a while loop around the
refresh to check for any new unrecognized commits
[#4927] ticket:185 put a while loop around the refresh to check for any new unrecognized commits
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ede9f523
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ede9f523
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ede9f523
Branch: refs/heads/cj/5094
Commit: ede9f523b8661a2699074db97816dd8511cce056
Parents: fb354e5
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Tue Oct 9 17:50:47 2012 +0300
Committer: Cory Johns <jo...@geek.net>
Committed: Mon Oct 15 20:23:07 2012 +0000
----------------------------------------------------------------------
Allura/allura/model/repository.py | 5 ++++-
Allura/allura/tasks/repo_tasks.py | 8 +++++++-
Allura/allura/tests/model/test_repo.py | 21 +++++++++++++++++++--
3 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ede9f523/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index aabaa61..99f9ba2 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -29,7 +29,7 @@ from .artifact import Artifact, VersionedArtifact, Feed
from .auth import User
from .session import repository_orm_session, project_orm_session
from .notification import Notification
-from .repo_refresh import refresh_repo
+from .repo_refresh import refresh_repo, unknown_commit_ids as unknown_commit_ids_repo
from .repo import CommitRunDoc, QSIZE
from .timeline import ActivityObject
@@ -403,6 +403,9 @@ class Repository(Artifact, ActivityObject):
content_type, encoding = 'application/octet-stream', None
return content_type, encoding
+ def unknown_commit_ids(self):
+ return unknown_commit_ids_repo(self.all_commit_ids())
+
def refresh(self, all_commits=False, notify=True):
'''Find any new commits in the repository and update'''
try:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ede9f523/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index f7bb7aa..7cfc463 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -89,6 +89,7 @@ def reclone(*args, **kwargs):
@task
def refresh(**kwargs):
from allura import model as M
+ #don't create multiple refresh tasks
q = {
'task_name': 'allura.tasks.repo_tasks.refresh',
'state': 'busy'
@@ -96,8 +97,13 @@ def refresh(**kwargs):
refresh_tasks_count = M.MonQTask.query.find(q).count()
q['state'] = 'ready'
refresh_tasks_count += M.MonQTask.query.find(q).count()
- if refresh_tasks_count == 0:
+ if refresh_tasks_count <= 1: #only this task
c.app.repo.refresh()
+ #checking if we have new commits arrived
+ #during refresh and re-queue task if so
+ new_commit_ids = c.app.repo.unknown_commit_ids()
+ if len(new_commit_ids) > 0:
+ refresh.post()
@task
def uninstall(**kwargs):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ede9f523/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 1dda265..a09c8ed 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -196,6 +196,7 @@ class TestRepo(_TestWithRepo):
self.repo._impl.refresh_heads = mock.Mock(side_effect=set_heads)
self.repo.shorthand_for_commit = lambda oid: '[' + str(oid) + ']'
self.repo.url_for_commit = lambda oid: '/ci/' + str(oid) + '/'
+
with mock.patch('allura.model.repo_refresh.g.post_event') as post_event:
self.repo.refresh()
post_event.assert_called_with(
@@ -204,11 +205,27 @@ class TestRepo(_TestWithRepo):
self.repo.refresh()
post_event.assert_called_with(
'repo_refreshed', commit_number=0, new=False)
+
with mock.patch('allura.model.repository.Repository.refresh') as refresh:
allura.tasks.repo_tasks.refresh.post()
+ with mock.patch('allura.model.repository.Repository.unknown_commit_ids') as unknown_commit_ids:
+ unknown_commit_ids.return_value = [1,2,3]
+ #there are new commits so refresh has to be called once
+ #and new refresh should be queued
+ M.MonQTask.run_ready()
+ refresh.assert_called_once_with()
+ q = {
+ 'task_name': 'allura.tasks.repo_tasks.refresh',
+ 'state': 'ready',
+ }
+ assert M.MonQTask.query.find(q).count() == 1
+ refresh.reset_mock()
+ #adding second task and checking if refresh is fired once
allura.tasks.repo_tasks.refresh.post()
- M.MonQTask.run_ready()
- refresh.assert_called_once()
+ with mock.patch('allura.lib.mail_util.SMTPClient.sendmail') as sendmail:
+ M.MonQTask.run_ready()
+ refresh.assert_called_once_with()
+
ThreadLocalORMSession.flush_all()
notifications = M.Notification.query.find().all()
for n in notifications: