diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 51e8984..0aca725 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1410,6 +1410,7 @@ def new_issue(session, repo, title, content, user, ticketfolder, issue_id=None, session.add(issue) # Make sure we won't have SQLAlchemy error before we create the issue session.flush() + session.commit() pagure.lib.git.update_git( issue, repo=repo, repofolder=ticketfolder) diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 2a9abe2..2a4ce2f 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -215,10 +215,20 @@ def update_git(obj, repo, repofolder): else: raise NotImplementedError('Unknown object type %s' % obj.isa) - return pagure.lib.tasks.update_git.delay( + queued = pagure.lib.tasks.update_git.delay( repo.name, repo.namespace, repo.user.username if repo.is_fork else None, ticketuid, requestuid) + _maybe_wait(queued) + return queued + + +def _maybe_wait(result): + """ Function to patch if one wants to wait for finish. + + This function should only ever be overridden by a few tests that depend on + counting and very precise timing. """ + pass def _update_git(obj, repo, repofolder): diff --git a/tests/test_pagure_flask_dump_load_ticket.py b/tests/test_pagure_flask_dump_load_ticket.py index 48ff558..83809b9 100644 --- a/tests/test_pagure_flask_dump_load_ticket.py +++ b/tests/test_pagure_flask_dump_load_ticket.py @@ -56,8 +56,10 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): self.app = pagure.APP.test_client() @patch('pagure.lib.notify.send_email') - def test_dumping_reloading_ticket(self, send_email): + @patch('pagure.lib.git._maybe_wait') + def test_dumping_reloading_ticket(self, mw, send_email): """ Test dumping a ticket into a JSON blob. """ + mw.side_effect = lambda result: result.get() send_email.return_value = True tests.create_projects(self.session) @@ -199,6 +201,12 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests): self.setUp() tests.create_projects(self.session) + # Create repo + self.gitrepo = os.path.join(self.path, 'tickets', 'test.git') + repopath = os.path.join(self.path, 'tickets') + os.makedirs(self.gitrepo) + pygit2.init_repository(self.gitrepo, bare=True) + pagure.lib.git.update_ticket_from_git( self.session, reponame='test',