[patchew-devel] [PATCH 3/7] testing: Optimized "testing-get" API call

Fam Zheng posted 7 patches 7 years, 2 months ago
[patchew-devel] [PATCH 3/7] testing: Optimized "testing-get" API call
Posted by Fam Zheng 7 years, 2 months ago
With "testing.ready" property, we immediately mark series as "ready to
test" when git apply is done, eliminating the need to do a relatively
heavy search query.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 mods/testing.py       | 22 +++++++++++++++++-----
 tests/test_testing.py |  1 +
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/mods/testing.py b/mods/testing.py
index 47933e2..80a22a5 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -23,7 +23,7 @@ import math
 from api.views import APILoginRequiredView
 from api.models import Message, Project, MessageProperty
 from api.search import SearchEngine
-from event import emit_event, declare_event
+from event import emit_event, declare_event, register_handler
 from patchew.logviewer import LogView
 from schema import *
 
@@ -112,6 +112,16 @@ class TestingModule(PatchewModule):
                       test="test name",
                       log="test log",
                       is_timeout="whether the test has timeout")
+        register_handler("SetProperty", self.on_set_property)
+
+    def on_set_property(self, evt, obj, name, value, old_value):
+        if ((isinstance(obj, Message) and obj.is_series_head) \
+            or isinstance(obj, Project)) \
+            and name in ("git.tag", "git.repo") \
+            and old_value is None \
+            and obj.get_property("git.tag") and obj.get_property("git.repo"):
+                self.remove_testing_properties(obj)
+                obj.set_property("testing.ready", 1)
 
     def remove_testing_properties(self, obj, test=""):
         for k in list(obj.get_properties().keys()):
@@ -174,6 +184,7 @@ class TestingModule(PatchewModule):
         all_tests = set([k for k, v in self.get_tests(obj).items() if v["enabled"]])
         if all_tests.issubset(done_tests):
             obj.set_property("testing.done", True)
+            obj.set_property("testing.ready", None)
         if all_tests.issubset(done_tests):
             obj.set_property("testing.tested-head", head)
         emit_event("TestingReport", tester=tester, user=user.username,
@@ -430,11 +441,12 @@ class TestingGetView(APILoginRequiredView):
         return po, td
 
     def _find_series_test(self, request, po, tester, capabilities):
-        se = SearchEngine()
-        q = se.search_series("is:applied", "not:old", "not:tested",
-                             "project:" + po.name)
+        q = MessageProperty.objects.filter(name="testing.ready",
+                                           value=1,
+                                           message__project=po)
         candidate = None
-        for s in q:
+        for prop in q:
+            s = prop.message
             test = self._find_applicable_test(request.user, po,
                                               tester, capabilities, s)
             if not test:
diff --git a/tests/test_testing.py b/tests/test_testing.py
index cca3513..300201b 100755
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -46,6 +46,7 @@ class TestingTest(PatchewTestCase):
         if log is not None:
             self.msg.set_property("testing.log.tests", log)
         self.msg.set_property("testing.done", True)
+        self.msg.set_property("testing.ready", None)
 
     def test_basic(self):
         self.api_login()
-- 
2.14.3


[patchew-devel] Re: [PATCH 3/7] testing: Optimized "testing-get" API call
Posted by Paolo Bonzini 7 years, 2 months ago
On 07/03/2018 09:46, Fam Zheng wrote:
> With "testing.ready" property, we immediately mark series as "ready to
> test" when git apply is done, eliminating the need to do a relatively
> heavy search query.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  mods/testing.py       | 22 +++++++++++++++++-----
>  tests/test_testing.py |  1 +
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/mods/testing.py b/mods/testing.py
> index 47933e2..80a22a5 100644
> --- a/mods/testing.py
> +++ b/mods/testing.py
> @@ -23,7 +23,7 @@ import math
>  from api.views import APILoginRequiredView
>  from api.models import Message, Project, MessageProperty
>  from api.search import SearchEngine
> -from event import emit_event, declare_event
> +from event import emit_event, declare_event, register_handler
>  from patchew.logviewer import LogView
>  from schema import *
>  
> @@ -112,6 +112,16 @@ class TestingModule(PatchewModule):
>                        test="test name",
>                        log="test log",
>                        is_timeout="whether the test has timeout")
> +        register_handler("SetProperty", self.on_set_property)
> +
> +    def on_set_property(self, evt, obj, name, value, old_value):
> +        if ((isinstance(obj, Message) and obj.is_series_head) \
> +            or isinstance(obj, Project)) \
> +            and name in ("git.tag", "git.repo") \
> +            and old_value is None \
> +            and obj.get_property("git.tag") and obj.get_property("git.repo"):
> +                self.remove_testing_properties(obj)
> +                obj.set_property("testing.ready", 1)

I wonder if we should already move this event towards the "result" model
that is used by the REST API.  In this case, the event could be
something like OnResultUpdate, with a name of "git" and a status of
"success".

Otherwise, this makes sense.

Paolo


[patchew-devel] Re: [PATCH 3/7] testing: Optimized "testing-get" API call
Posted by Fam Zheng 7 years, 2 months ago
On Wed, 03/07 14:17, Paolo Bonzini wrote:
> On 07/03/2018 09:46, Fam Zheng wrote:
> > With "testing.ready" property, we immediately mark series as "ready to
> > test" when git apply is done, eliminating the need to do a relatively
> > heavy search query.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  mods/testing.py       | 22 +++++++++++++++++-----
> >  tests/test_testing.py |  1 +
> >  2 files changed, 18 insertions(+), 5 deletions(-)
> > 
> > diff --git a/mods/testing.py b/mods/testing.py
> > index 47933e2..80a22a5 100644
> > --- a/mods/testing.py
> > +++ b/mods/testing.py
> > @@ -23,7 +23,7 @@ import math
> >  from api.views import APILoginRequiredView
> >  from api.models import Message, Project, MessageProperty
> >  from api.search import SearchEngine
> > -from event import emit_event, declare_event
> > +from event import emit_event, declare_event, register_handler
> >  from patchew.logviewer import LogView
> >  from schema import *
> >  
> > @@ -112,6 +112,16 @@ class TestingModule(PatchewModule):
> >                        test="test name",
> >                        log="test log",
> >                        is_timeout="whether the test has timeout")
> > +        register_handler("SetProperty", self.on_set_property)
> > +
> > +    def on_set_property(self, evt, obj, name, value, old_value):
> > +        if ((isinstance(obj, Message) and obj.is_series_head) \
> > +            or isinstance(obj, Project)) \
> > +            and name in ("git.tag", "git.repo") \
> > +            and old_value is None \
> > +            and obj.get_property("git.tag") and obj.get_property("git.repo"):
> > +                self.remove_testing_properties(obj)
> > +                obj.set_property("testing.ready", 1)
> 
> I wonder if we should already move this event towards the "result" model
> that is used by the REST API.  In this case, the event could be
> something like OnResultUpdate, with a name of "git" and a status of
> "success".

Sounds okay, but where to generate the event? Current result data is not
structured, but I'm also reluctant to encapsulate the 'git.*' properties into a
'results.git' dict property, making it a second class citizen.

Fam

[patchew-devel] Re: [PATCH 3/7] testing: Optimized "testing-get" API call
Posted by Fam Zheng 7 years, 1 month ago
On Wed, 03/07 14:17, Paolo Bonzini wrote:
> On 07/03/2018 09:46, Fam Zheng wrote:
> > With "testing.ready" property, we immediately mark series as "ready to
> > test" when git apply is done, eliminating the need to do a relatively
> > heavy search query.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  mods/testing.py       | 22 +++++++++++++++++-----
> >  tests/test_testing.py |  1 +
> >  2 files changed, 18 insertions(+), 5 deletions(-)
> > 
> > diff --git a/mods/testing.py b/mods/testing.py
> > index 47933e2..80a22a5 100644
> > --- a/mods/testing.py
> > +++ b/mods/testing.py
> > @@ -23,7 +23,7 @@ import math
> >  from api.views import APILoginRequiredView
> >  from api.models import Message, Project, MessageProperty
> >  from api.search import SearchEngine
> > -from event import emit_event, declare_event
> > +from event import emit_event, declare_event, register_handler
> >  from patchew.logviewer import LogView
> >  from schema import *
> >  
> > @@ -112,6 +112,16 @@ class TestingModule(PatchewModule):
> >                        test="test name",
> >                        log="test log",
> >                        is_timeout="whether the test has timeout")
> > +        register_handler("SetProperty", self.on_set_property)
> > +
> > +    def on_set_property(self, evt, obj, name, value, old_value):
> > +        if ((isinstance(obj, Message) and obj.is_series_head) \
> > +            or isinstance(obj, Project)) \
> > +            and name in ("git.tag", "git.repo") \
> > +            and old_value is None \
> > +            and obj.get_property("git.tag") and obj.get_property("git.repo"):
> > +                self.remove_testing_properties(obj)
> > +                obj.set_property("testing.ready", 1)
> 
> I wonder if we should already move this event towards the "result" model
> that is used by the REST API.  In this case, the event could be
> something like OnResultUpdate, with a name of "git" and a status of
> "success".
> 
> Otherwise, this makes sense.

I'm merging this series now and let's work on the result model refactoring on
top.

Fam