Should fetch owner commits in build-requests-fetcher.
authordewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jan 2018 10:07:04 +0000 (10:07 +0000)
committerdewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jan 2018 10:07:04 +0000 (10:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182266

Reviewed by Ryosuke Niwa.

In a build request, owner commit of a commit is not always one of a commit in the commit set.
Build request api should contain owner commits in the 'commits' field of the return value.

* public/include/build-requests-fetcher.php: Added logic to fetch owner commits and added them into 'commits'.
* server-tests/api-build-requests-tests.js: Added a unit test.
* server-tests/resources/mock-data.js:
(MockData.set addTestGroupWithOwnerCommitNotInCommitSet): Added a test group with a build request, the commit set of which does
not contain owner commit of one commit.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227777 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/include/build-requests-fetcher.php
Websites/perf.webkit.org/server-tests/api-build-requests-tests.js
Websites/perf.webkit.org/server-tests/resources/mock-data.js

index 8d001f8..b86fcc6 100644 (file)
@@ -1,3 +1,19 @@
+2018-01-29  Dewei Zhu  <dewei_zhu@apple.com>
+
+        Should fetch owner commits in build-requests-fetcher.
+        https://bugs.webkit.org/show_bug.cgi?id=182266
+
+        Reviewed by Ryosuke Niwa.
+
+        In a build request, owner commit of a commit is not always one of a commit in the commit set.
+        Build request api should contain owner commits in the 'commits' field of the return value.
+
+        * public/include/build-requests-fetcher.php: Added logic to fetch owner commits and added them into 'commits'.
+        * server-tests/api-build-requests-tests.js: Added a unit test.
+        * server-tests/resources/mock-data.js:
+        (MockData.set addTestGroupWithOwnerCommitNotInCommitSet): Added a test group with a build request, the commit set of which does
+        not contain owner commit of one commit.
+
 2018-01-29  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add the support for reporting Speedometer 2.0 results to perf dashboard
index ed999c4..27f0240 100644 (file)
@@ -144,6 +144,25 @@ class BuildRequestsFetcher {
 
         $this->commit_sets_by_id[$commit_set_id] = TRUE;
 
+        $owner_commits_rows = $this->db->query_and_fetch_all('SELECT * FROM commits, repositories
+            WHERE commit_repository = repository_id AND  commit_id
+            IN (SELECT DISTINCT(commitset_commit_owner) FROM commit_set_items
+              WHERE commitset_set = $1 AND commitset_commit_owner IS NOT NULL)', array($commit_set_id));
+
+        foreach ($owner_commits_rows as $row) {
+            $commit_id = $row['commit_id'];
+            if (array_key_exists($commit_id, $this->commits_by_id))
+                continue;
+
+            array_push($this->commits, array(
+                'id' => $commit_id,
+                'repository' => $resolve_ids ? $row['repository_name'] : $row['repository_id'],
+                'commitOwner' => NULL,
+                'revision' => $row['commit_revision'],
+                'time' => Database::to_js_time($row['commit_time'])));
+            $this->commits_by_id[$commit_id] = TRUE;
+        }
+
         array_push($this->commit_sets, array('id' => $commit_set_id, 'revisionItems' => $revision_items, 'customRoots' => $custom_roots));
     }
 
index 1fa0146..80ceaf7 100644 (file)
@@ -281,6 +281,50 @@ describe('/api/build-requests', function () {
         });
     });
 
+    it('a repository group of a build request should accepts the commit set of the same build request', async () => {
+        await MockData.addTestGroupWithOwnerCommitNotInCommitSet(TestServer.database());
+        await Manifest.fetch();
+        const buildRequests = await BuildRequest.fetchForTriggerable('build-webkit');
+        assert.equal(buildRequests.length, 1);
+
+        const test = Test.findById(200);
+        assert(test);
+
+        const platform = Platform.findById(65);
+        assert(platform);
+
+        const buildRequest = buildRequests[0];
+
+        assert.equal(buildRequest.id(), 704);
+        assert.equal(buildRequest.testGroupId(), 900);
+        assert.equal(buildRequest.test(), test);
+        assert.equal(buildRequest.platform(), platform);
+        assert.equal(buildRequest.order(), 0);
+        assert.ok(buildRequest.commitSet() instanceof CommitSet);
+        assert.ok(!buildRequest.hasFinished());
+        assert.ok(!buildRequest.hasStarted());
+        assert.ok(buildRequest.isPending());
+        assert.equal(buildRequest.statusLabel(), 'Waiting');
+
+        const osx = Repository.findById(9);
+        assert.equal(osx.name(), 'macOS');
+
+        const webkit = Repository.findById(11);
+        assert.equal(webkit.name(), 'WebKit');
+
+        const jsc = Repository.findById(213);
+        assert.equal(jsc.name(), 'JavaScriptCore');
+
+        const commitSet = buildRequest.commitSet();
+
+        assert.equal(commitSet.revisionForRepository(osx), '10.11 15A284');
+        assert.equal(commitSet.revisionForRepository(webkit), '192736');
+        assert.equal(commitSet.revisionForRepository(jsc), 'owned-jsc-9191');
+        assert.equal(commitSet.ownerRevisionForRepository(jsc), '191622');
+        assert.deepEqual(commitSet.topLevelRepositories().sort((one, another) => one.id() < another.id()), [osx, webkit]);
+        assert.ok(buildRequest.repositoryGroup().accepts(commitSet));
+    });
+
     it('should be fetchable by BuildRequest.fetchForTriggerable', () => {
         return MockData.addMockData(TestServer.database()).then(() => {
             return Manifest.fetch();
index be1c734..11e1d8d 100644 (file)
@@ -161,6 +161,22 @@ MockData = {
             db.insert('build_requests', {id: 707, status: statusList[3], triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 3, commit_set: 404}),
         ]);
     },
+    addTestGroupWithOwnerCommitNotInCommitSet(db)
+    {
+        return Promise.all([
+            this.addMockConfiguration(db),
+            this.addAnotherTriggerable(db),
+            db.insert('analysis_tasks', {id: 1080, platform: 65, metric: 300, name: 'some task with component test',
+                start_run: 801, start_run_time: '2015-10-27T12:05:27.1Z',
+                end_run: 801, end_run_time: '2015-10-27T12:05:27.1Z'}),
+            db.insert('analysis_test_groups', {id: 900, task: 1080, name: 'some test group with component test'}),
+            db.insert('commit_sets', {id: 404}),
+            db.insert('commit_set_items', {set: 404, commit: 87832}),
+            db.insert('commit_set_items', {set: 404, commit: 96336}),
+            db.insert('commit_set_items', {set: 404, commit: 2017, commit_owner: 93116, requires_build: true}),
+            db.insert('build_requests', {id: 704, status: 'pending', triggerable: 1000, repository_group: 2001, platform: 65, test: 200, group: 900, order: 0, commit_set: 404}),
+        ]);
+    },
     mockTestSyncConfigWithSingleBuilder: function ()
     {
         return {