From a155e32a6f50bc298fe2db074fdbc975d5d986b2 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 25 May 2021 13:53:24 +0300 Subject: [PATCH 1/4] Simplify getting subtype logic --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index b0a3ca8..07c400f 100644 --- a/server.py +++ b/server.py @@ -260,7 +260,7 @@ def post(self): changed_item_ids = self.item_ids(changes) if type(tests) == dict: repository = tests['repository'] - subtype = tests['subtype'] if 'subtype' in tests else 'default' + subtype = tests.get('subtype', 'default') prioritized = yield self.async_query(self.async_db.prioritize, context, repository, subtype, changed_item_ids) elif type(tests) == list: From 1f5ec164de8a8e92c1386046799412f104432aef Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 18 Jun 2021 09:31:04 +0300 Subject: [PATCH 2/4] For prioritize sql query use LIKE operator for context Tis allows to use context like FOO% instad of FOOBAR. --- sql_queries.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sql_queries.py b/sql_queries.py index 607bd74..2c6a5e8 100644 --- a/sql_queries.py +++ b/sql_queries.py @@ -32,6 +32,7 @@ SET status=%(status)s, fingerprint=%(fingerprint)s, last_updated='now', execution_id=%(execution_id)s """ + def update_links(alpha, strength, effected_item, changed_items): VALUES_ROW = "({effected_item}, {strength}, {changed_item}, %(context)s, 'now')" value_rows = [] @@ -48,6 +49,7 @@ def update_links(alpha, strength, effected_item, changed_items): alpha=float(alpha), strength=float(strength)) + TEST_ID_SUBQUERY = """ SELECT id FROM item @@ -56,15 +58,16 @@ def update_links(alpha, strength, effected_item, changed_items): AND subtype=%(subtype)s """ + def prioritize(use_test_list=True): return """ SELECT item.id, item.name, repository, item_type, subtype, status, sum(strength) as strength FROM item LEFT OUTER JOIN previous_status ON previous_status.test=item.id - AND previous_status.context=%(context)s + AND previous_status.context LIKE %(context)s LEFT OUTER JOIN link ON link.effected_item=item.id - AND link.context=%(context)s + AND link.context LIKE %(context)s AND link.changed_item IN %(changed_item_ids)s WHERE item.id IN {test_ids} GROUP BY item.id, item.name, repository, item_type, subtype, status From d956a75bc895fece157d5a1085cc4fbec4cd8ead Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 18 Jun 2021 09:52:08 +0300 Subject: [PATCH 3/4] Simplify gettting context for PrioritizeHandler --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 07c400f..c9a45e4 100644 --- a/server.py +++ b/server.py @@ -256,7 +256,7 @@ def post(self): data = json.loads(self.request.body) tests = data['tests'] changes = data['changes'] - context = data['context'] if 'context' in data else 'default' + context = data.get('context', 'default') changed_item_ids = self.item_ids(changes) if type(tests) == dict: repository = tests['repository'] From 942a15c65061e5c1867e071e8602a346120907c5 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Fri, 18 Jun 2021 09:53:21 +0300 Subject: [PATCH 4/4] Add description for prioritization api --- README.md | 1 + prioritization_api.md | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 prioritization_api.md diff --git a/README.md b/README.md index 013a405..6bacb1e 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ robot --argumentfile prioritized.robot --metadata changes:"$(YOUR_GIT_COMMAND_LI robot --argumentfile remnant.robot --metadata changes:"$(YOUR_GIT_COMMAND_LISTING_RELEVANT_CHANGES)" --metadata commit:$(git rev-parse HEAD) tests/ ``` +For more details about the data expected by the prioritization API see [prioritization_api.md](prioritization_api.md). ## Swagger docs diff --git a/prioritization_api.md b/prioritization_api.md new file mode 100644 index 0000000..1c764ee --- /dev/null +++ b/prioritization_api.md @@ -0,0 +1,23 @@ +#Querying tests from sinle repository + +The body looks similar as in the [feeding.api](feeding_api.md), because API is also using the `changes` and the +`context` keys in identical manner. But because API is querying test, we do not the `tests` contains only the +`repository` and `subtype` keys. + +``` +{ + "context": "the execution context (e.g. from which pipeline to not mix results from parallel tests. Supports LIKE operator from SQL engine, example %)" , + "tests": { + "repository": "Repository ", + "subtype": "type of test (optional, for separating test cases and for filtering subsets when prioritising", + }, + "changes": [ + { + "name": "string representing the changed item, for example file path", + "repository": "repository (optional, for separating between changed items with identical names)", + "item_type": "(optional, for separating items and for filtering subsets when prioritising)", + "subtype": "(optional, for separating items for filtering subsets when prioritising" + } + ] +} +```