-
-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] queue_job: Add split method #658
Open
paradoxxxzero
wants to merge
3
commits into
OCA:14.0
Choose a base branch
from
akretion:14.0-imp-queue_job-split
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# copyright 2019 Camptocamp | ||
# license agpl-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import unittest | ||
|
||
import mock | ||
|
||
from odoo.tests import common | ||
|
||
# pylint: disable=odoo-addons-relative-import | ||
from odoo.addons.queue_job.delay import Delayable, DelayableGraph | ||
|
||
|
||
class TestDelayable(unittest.TestCase): | ||
class TestDelayable(common.TransactionCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no transaction required here. Use TestCase or BaseCase |
||
def setUp(self): | ||
super().setUp() | ||
self.recordset = mock.MagicMock(name="recordset") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests import common | ||
|
||
# pylint: disable=odoo-addons-relative-import | ||
from odoo.addons.queue_job.delay import Delayable | ||
|
||
|
||
class TestDelayableSplit(common.TransactionCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same regarding the base class |
||
def setUp(self): | ||
super().setUp() | ||
|
||
class FakeRecordSet(list): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._name = "recordset" | ||
|
||
def __getitem__(self, key): | ||
if isinstance(key, slice): | ||
return FakeRecordSet(super().__getitem__(key)) | ||
return super().__getitem__(key) | ||
|
||
def method(self, arg, kwarg=None): | ||
"""Method to be called""" | ||
return arg, kwarg | ||
|
||
self.FakeRecordSet = FakeRecordSet | ||
|
||
def test_delayable_split_no_method_call_beforehand(self): | ||
dl = Delayable(self.FakeRecordSet(range(20))) | ||
with self.assertRaises(ValueError): | ||
dl.split(3) | ||
|
||
def test_delayable_split_10_3(self): | ||
dl = Delayable(self.FakeRecordSet(range(10))) | ||
dl.method("arg", kwarg="kwarg") | ||
group = dl.split(3) | ||
self.assertEqual(len(group._delayables), 4) | ||
delayables = sorted(list(group._delayables), key=lambda x: x.description) | ||
self.assertEqual(delayables[0].recordset, self.FakeRecordSet([0, 1, 2])) | ||
self.assertEqual(delayables[1].recordset, self.FakeRecordSet([3, 4, 5])) | ||
self.assertEqual(delayables[2].recordset, self.FakeRecordSet([6, 7, 8])) | ||
self.assertEqual(delayables[3].recordset, self.FakeRecordSet([9])) | ||
self.assertEqual(delayables[0].description, "Method to be called (split 1/4)") | ||
self.assertEqual(delayables[1].description, "Method to be called (split 2/4)") | ||
self.assertEqual(delayables[2].description, "Method to be called (split 3/4)") | ||
self.assertEqual(delayables[3].description, "Method to be called (split 4/4)") | ||
self.assertNotEqual(delayables[0]._job_method, dl._job_method) | ||
self.assertNotEqual(delayables[1]._job_method, dl._job_method) | ||
self.assertNotEqual(delayables[2]._job_method, dl._job_method) | ||
self.assertNotEqual(delayables[3]._job_method, dl._job_method) | ||
self.assertEqual(delayables[0]._job_method.__name__, dl._job_method.__name__) | ||
self.assertEqual(delayables[1]._job_method.__name__, dl._job_method.__name__) | ||
self.assertEqual(delayables[2]._job_method.__name__, dl._job_method.__name__) | ||
self.assertEqual(delayables[3]._job_method.__name__, dl._job_method.__name__) | ||
self.assertEqual(delayables[0]._job_args, ("arg",)) | ||
self.assertEqual(delayables[1]._job_args, ("arg",)) | ||
self.assertEqual(delayables[2]._job_args, ("arg",)) | ||
self.assertEqual(delayables[3]._job_args, ("arg",)) | ||
self.assertEqual(delayables[0]._job_kwargs, {"kwarg": "kwarg"}) | ||
self.assertEqual(delayables[1]._job_kwargs, {"kwarg": "kwarg"}) | ||
self.assertEqual(delayables[2]._job_kwargs, {"kwarg": "kwarg"}) | ||
self.assertEqual(delayables[3]._job_kwargs, {"kwarg": "kwarg"}) | ||
|
||
def test_delayable_split_10_5(self): | ||
dl = Delayable(self.FakeRecordSet(range(10))) | ||
dl.method("arg", kwarg="kwarg") | ||
group = dl.split(5) | ||
self.assertEqual(len(group._delayables), 2) | ||
delayables = sorted(list(group._delayables), key=lambda x: x.description) | ||
self.assertEqual(delayables[0].recordset, self.FakeRecordSet([0, 1, 2, 3, 4])) | ||
self.assertEqual(delayables[1].recordset, self.FakeRecordSet([5, 6, 7, 8, 9])) | ||
self.assertEqual(delayables[0].description, "Method to be called (split 1/2)") | ||
self.assertEqual(delayables[1].description, "Method to be called (split 2/2)") | ||
|
||
def test_delayable_split_10_10(self): | ||
dl = Delayable(self.FakeRecordSet(range(10))) | ||
dl.method("arg", kwarg="kwarg") | ||
group = dl.split(10) | ||
self.assertEqual(len(group._delayables), 1) | ||
delayables = sorted(list(group._delayables), key=lambda x: x.description) | ||
self.assertEqual(delayables[0].recordset, self.FakeRecordSet(range(10))) | ||
self.assertEqual(delayables[0].description, "Method to be called (split 1/1)") | ||
|
||
def test_delayable_split_10_20(self): | ||
dl = Delayable(self.FakeRecordSet(range(10))) | ||
dl.method("arg", kwarg="kwarg") | ||
group = dl.split(20) | ||
self.assertEqual(len(group._delayables), 1) | ||
delayables = sorted(list(group._delayables), key=lambda x: x.description) | ||
self.assertEqual(delayables[0].recordset, self.FakeRecordSet(range(10))) | ||
self.assertEqual(delayables[0].description, "Method to be called (split 1/1)") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.