Fix a bug in syncing script that test/build syncer is never set.
authordewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 19:48:57 +0000 (19:48 +0000)
committerdewei_zhu@apple.com <dewei_zhu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Oct 2017 19:48:57 +0000 (19:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178772

Reviewed by Ryosuke Niwa.

Neither 'buildSyncer' nor 'testSyncer' is ever set.
Added a unit test to cover this case.

* server-tests/tools-sync-buildbot-integration-tests.js:
(createTriggerable): Refactor it to allow customized name.
* tools/js/buildbot-triggerable.js:
(BuildbotTriggerable.prototype._pullBuildbotOnAllSyncers): Update syncer info accordingly.
(BuildbotTriggerable._testGroupMapForBuildRequests): Initialize build and test syncer to null.

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

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/server-tests/tools-sync-buildbot-integration-tests.js
Websites/perf.webkit.org/tools/js/buildbot-triggerable.js

index 872ade8..dbd5f42 100644 (file)
@@ -1,5 +1,21 @@
 2017-10-24  Dewei Zhu  <dewei_zhu@apple.com>
 
+        Fix a bug in syncing script that test/build syncer is never set.
+        https://bugs.webkit.org/show_bug.cgi?id=178772
+
+        Reviewed by Ryosuke Niwa.
+
+        Neither 'buildSyncer' nor 'testSyncer' is ever set.
+        Added a unit test to cover this case.
+
+        * server-tests/tools-sync-buildbot-integration-tests.js:
+        (createTriggerable): Refactor it to allow customized name.
+        * tools/js/buildbot-triggerable.js:
+        (BuildbotTriggerable.prototype._pullBuildbotOnAllSyncers): Update syncer info accordingly.
+        (BuildbotTriggerable._testGroupMapForBuildRequests): Initialize build and test syncer to null.
+
+2017-10-24  Dewei Zhu  <dewei_zhu@apple.com>
+
         Owner commit does not necessarily exist in the same commit set for an owned commit.
         https://bugs.webkit.org/show_bug.cgi?id=178763
 
index b46529a..f159e3e 100644 (file)
@@ -13,52 +13,90 @@ const TemporaryFile = require('./resources/temporary-file.js').TemporaryFile;
 const addSlaveForReport = require('./resources/common-operations.js').addSlaveForReport;
 const prepareServerTest = require('./resources/common-operations.js').prepareServerTest;
 
-function createTriggerable()
+const configWithOneTesterTwoBuilders = {
+    triggerableName: 'build-webkit',
+    lookbackCount: 2,
+    buildRequestArgument: 'build-request-id',
+    slaveName: 'sync-slave',
+    slavePassword: 'password',
+    repositoryGroups: {
+        'webkit': {
+            repositories: {'WebKit': {acceptsPatch: true}},
+            testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
+            buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
+                'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
+                'owned-commits': {'ownedRevisions': 'WebKit'}},
+            acceptsRoots: true,
+        }
+    },
+    types: {
+        'some': {
+            test: ['some test'],
+            properties: {'test': 'some-test'},
+        }
+    },
+    builders: {
+        'builder-1': {
+            builder: 'some tester',
+            properties: {forcescheduler: 'force-ab-tests'},
+        },
+        'builder-2': {
+            builder: 'some builder',
+            properties: {forcescheduler: 'force-ab-builds'},
+        },
+        'builder-3': {
+            builder: 'other builder',
+            properties: {forcescheduler: 'force-ab-builds'},
+        },
+    },
+    buildConfigurations: [
+        {platforms: ['some platform'], builders: ['builder-2', 'builder-3']},
+    ],
+    testConfigurations: [
+        {types: ['some'], platforms: ['some platform'], builders: ['builder-1']},
+    ],
+};
+
+const configWithTwoTesters = {
+    triggerableName: 'build-webkit',
+    lookbackCount: 2,
+    buildRequestArgument: 'build-request-id',
+    slaveName: 'sync-slave',
+    slavePassword: 'password',
+    repositoryGroups: {
+        'webkit': {
+            repositories: {'WebKit': {acceptsPatch: true}},
+            testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
+            buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
+                'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
+                'owned-commits': {'ownedRevisions': 'WebKit'}},
+            acceptsRoots: true,
+        }
+    },
+    types: {
+        'some': {
+            test: ['some test'],
+            properties: {'test': 'some-test'},
+        }
+    },
+    builders: {
+        'builder-1': {
+            builder: 'some tester',
+            properties: {forcescheduler: 'force-ab-tests'},
+        },
+        'builder-2': {
+            builder: 'another tester',
+            properties: {forcescheduler: 'force-ab-builds'},
+        },
+    },
+    testConfigurations: [
+        {types: ['some'], platforms: ['some platform'], builders: ['builder-1', 'builder-2']},
+    ]
+};
+
+function createTriggerable(config = configWithOneTesterTwoBuilders)
 {
     let triggerable;
-    const config = {
-            triggerableName: 'build-webkit',
-            lookbackCount: 2,
-            buildRequestArgument: 'build-request-id',
-            slaveName: 'sync-slave',
-            slavePassword: 'password',
-            repositoryGroups: {
-                'webkit': {
-                    repositories: {'WebKit': {acceptsPatch: true}},
-                    testProperties: {'wk': {'revision': 'WebKit'}, 'roots': {'roots': {}}},
-                    buildProperties: {'wk': {'revision': 'WebKit'}, 'wk-patch': {'patch': 'WebKit'},
-                        'checkbox': {'ifRepositorySet': ['WebKit'], 'value': 'build-wk'},
-                        'owned-commits': {'ownedRevisions': 'WebKit'}},
-                    acceptsRoots: true,
-                }
-            },
-            types: {
-                'some': {
-                    test: ['some test'],
-                    properties: {'test': 'some-test'},
-                }
-            },
-            builders: {
-                'builder-1': {
-                    builder: 'some tester',
-                    properties: {forcescheduler: 'force-ab-tests'},
-                },
-                'builder-2': {
-                    builder: 'some builder',
-                    properties: {forcescheduler: 'force-ab-builds'},
-                },
-                'builder-3': {
-                    builder: 'other builder',
-                    properties: {forcescheduler: 'force-ab-builds'},
-                },
-            },
-            buildConfigurations: [
-                {platforms: ['some platform'], builders: ['builder-2', 'builder-3']},
-            ],
-            testConfigurations: [
-                {types: ['some'], platforms: ['some platform'], builders: ['builder-1']},
-            ],
-        };
     return MockData.addMockConfiguration(TestServer.database()).then(() => {
         return Manifest.fetch();
     }).then(() => {
@@ -69,6 +107,18 @@ function createTriggerable()
     });
 }
 
+function createTestGroup(task_name='custom task') {
+    const someTest = Test.findById(MockData.someTestId());
+    const webkit = Repository.findById(MockData.webkitRepositoryId());
+    const set1 = new CustomCommitSet;
+    set1.setRevisionForRepository(webkit, '191622');
+    const set2 = new CustomCommitSet;
+    set2.setRevisionForRepository(webkit, '192736');
+    return TestGroup.createWithTask('custom task', Platform.findById(MockData.somePlatformId()), someTest, 'some group', 2, [set1, set2]).then((task) => {
+        return TestGroup.findAllByTask(task.id())[0];
+    });
+}
+
 function createTestGroupWihPatch()
 {
     return TemporaryFile.makeTemporaryFile('patch.dat', 'patch file').then((patchFile) => {
@@ -133,6 +183,93 @@ describe('sync-buildbot', function () {
         request.resolve(contentToResolve);
     }
 
+    it('should not schedule on another builder if the build was scheduled on one builder before', () => {
+        const requests = MockRemoteAPI.requests;
+        let firstTestGroup;
+        let secondTestGroup;
+        let syncPromise;
+        let triggerable;
+        let taskId = null;
+        let anotherTaskId = null;
+        return createTriggerable(configWithTwoTesters).then((newTriggerable) => {
+            triggerable = newTriggerable;
+            return Promise.all([createTestGroup(), createTestGroup('another custom task')]);
+        }).then((testGroups) => {
+            firstTestGroup = testGroups[0];
+            secondTestGroup = testGroups[1];
+            taskId = firstTestGroup.task().id();
+            anotherTaskId = secondTestGroup.task().id();
+            syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());
+            return MockRemoteAPI.waitForRequest();
+        }).then(() => {
+            assert.equal(requests.length, 2);
+            assertAndResolveRequest(requests[0], 'GET', '/json/builders/some%20tester/pendingBuilds', [MockData.pendingBuild({builder: 'some tester', buildRequestId: 5})]);
+            assertAndResolveRequest(requests[1], 'GET', '/json/builders/another%20tester/pendingBuilds', []);
+            return MockRemoteAPI.waitForRequest();
+        }).then(() => {
+            assert.equal(requests.length, 4);
+            assertAndResolveRequest(requests[2], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {
+                [-1]: MockData.runningBuild({builder: 'some tester', buildRequestId: 1})});
+            assertAndResolveRequest(requests[3], 'GET', '/json/builders/another%20tester/builds/?select=-1&select=-2', {});
+            return MockRemoteAPI.waitForRequest();
+        }).then(() => {
+            assert.equal(requests.length, 6);
+            assertAndResolveRequest(requests[4], 'GET', '/json/builders/some%20tester/pendingBuilds', []);
+            assertAndResolveRequest(requests[5], 'GET', '/json/builders/another%20tester/pendingBuilds',[]);
+            return MockRemoteAPI.waitForRequest();
+        }).then(() => {
+            assert.equal(requests.length, 8);
+            assertAndResolveRequest(requests[6], 'GET', '/json/builders/some%20tester/builds/?select=-1&select=-2', {
+                [-1]: MockData.runningBuild({builder: 'some tester', buildRequestId: 5}),
+                [-2]: MockData.finishedBuild({builder: 'some tester', buildRequestId: 1})
+            });
+            assertAndResolveRequest(requests[7], 'GET', '/json/builders/another%20tester/builds/?select=-1&select=-2', {});
+            return syncPromise;
+        }).then(() => {
+            return TestGroup.fetchForTask(taskId, true);
+        }).then((testGroups) => {
+            assert.equal(testGroups.length, 1);
+            const testGroup = testGroups[0];
+            const webkit = Repository.findById(MockData.webkitRepositoryId());
+
+            const buildRequest = testGroup.buildRequests()[0];
+            assert.equal(testGroup.buildRequests().length, 4);
+            assert(!buildRequest.isBuild());
+            assert(buildRequest.isTest());
+
+            const commitSet = buildRequest.commitSet();
+            assert.equal(commitSet.revisionForRepository(webkit), '191622');
+
+            const otherBuildRequest = testGroup.buildRequests()[1];
+            assert(!otherBuildRequest.isBuild());
+            assert(otherBuildRequest.isTest());
+
+            const otherCommitSet = otherBuildRequest.commitSet();
+            assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
+
+            return TestGroup.fetchForTask(anotherTaskId, true);
+        }).then((testGroups) => {
+            assert.equal(testGroups.length, 1);
+            const testGroup = testGroups[0];
+            const webkit = Repository.findById(MockData.webkitRepositoryId());
+
+            const buildRequest = testGroup.buildRequests()[0];
+            assert.equal(testGroup.buildRequests().length, 4);
+            assert(!buildRequest.isBuild());
+            assert(buildRequest.isTest());
+
+            const commitSet = buildRequest.commitSet();
+            assert.equal(commitSet.revisionForRepository(webkit), '191622');
+
+            const otherBuildRequest = testGroup.buildRequests()[1];
+            assert(!otherBuildRequest.isBuild());
+            assert(otherBuildRequest.isTest());
+
+            const otherCommitSet = otherBuildRequest.commitSet();
+            assert.equal(otherCommitSet.revisionForRepository(webkit), '192736');
+        });
+    });
+
     it('should schedule a build to build a patch', () => {
         const requests = MockRemoteAPI.requests;
         let triggerable;
index 1bf191d..10352aa 100644 (file)
@@ -154,17 +154,19 @@ class BuildbotTriggerable {
 
                     const info = buildReqeustsByGroup.get(request.testGroupId());
                     if (request.isBuild()) {
-                        assert(!info.buildSyncer || info.buildSyncer == buildSyncer);
+                        assert(!info.buildSyncer || info.buildSyncer == syncer);
                         if (entry.slaveName()) {
                             assert(!info.buildSlaveName || info.buildSlaveName == entry.slaveName());
                             info.buildSlaveName = entry.slaveName();
                         }
+                        info.buildSyncer = syncer;
                     } else {
-                        assert(!info.testSyncer || info.testSyncer == testSyncer);
+                        assert(!info.testSyncer || info.testSyncer == syncer);
                         if (entry.slaveName()) {
                             assert(!info.testSlaveName || info.testSlaveName == entry.slaveName());
                             info.testSlaveName = entry.slaveName();
                         }
+                        info.testSyncer = syncer;
                     }
 
                     const newStatus = entry.buildRequestStatusIfUpdateIsNeeded(request);
@@ -238,7 +240,7 @@ class BuildbotTriggerable {
         for (let request of buildRequests) {
             let groupId = request.testGroupId();
             if (!map.has(groupId)) // Don't use real TestGroup objects to avoid executing postgres query in the server
-                map.set(groupId, {id: groupId, groupOrder: groupOrder++, requests: [request], syncer: null, slaveName: null});
+                map.set(groupId, {id: groupId, groupOrder: groupOrder++, requests: [request], buildSyncer: null, testSyncer: null, slaveName: null});
             else
                 map.get(groupId).requests.push(request);
         }