haikuwebkit/Websites/perf.webkit.org/unit-tests/analysis-results-notifier-t...

296 lines
20 KiB
JavaScript
Raw Permalink Normal View History

Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
'use strict';
global.CommonComponentBase = require('../public/shared/common-component-base.js').CommonComponentBase;
global.MarkupPage = require('../tools/js/markup-component.js').MarkupPage;
global.MarkupComponentBase = require('../tools/js/markup-component.js').MarkupComponentBase;
const assert = require('assert');
const MockRemoteAPI = require('./resources/mock-remote-api.js').MockRemoteAPI;
const AnalysisResultsNotifier = require('../tools/js/analysis-results-notifier.js').AnalysisResultsNotifier;
const assertThrows = require('../server-tests/resources/common-operations.js').assertThrows;
describe('AnalysisResultsNotifier', () => {
describe('_matchesRule', () => {
const trunkMacBook = 'Trunk MacBook';
const trunkMacBookPro = 'Trunk MacBook Pro';
const trunkMacBookAir = 'Trunk MacBook Air';
const speedometer = 'speedometer';
const speedometer2 = 'speedometer-2';
const jetStream = 'JetStream';
it('should return a group of matching function based on configuration', () => {
const rule = {platforms: [trunkMacBook, trunkMacBookPro], tests: [speedometer, speedometer2]};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, true, rule));
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
it('should match rule only contains tests correctly', () => {
const rule = {tests: [jetStream]};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, jetStream, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, true, rule));
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
it('should match rule only contains platforms correctly', () => {
const rule = {platforms: [trunkMacBook]};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, jetStream, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, true, rule));
});
it('should match rule with "userInitiated" set to true', () => {
const rule = {platforms: [trunkMacBook, trunkMacBookPro], tests: [speedometer, speedometer2], userInitiated: true};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
});
it('should match rule with "userInitiated" set to false', () => {
const rule = {platforms: [trunkMacBook, trunkMacBookPro], tests: [speedometer, speedometer2], userInitiated: false};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
it('should match the rule regardless whether or not "userInitiated" is set if rule does not specify', () => {
const rule = {platforms: [trunkMacBook, trunkMacBookPro], tests: [speedometer, speedometer2]};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
});
perf.webkit.org/tools/js/analysis-results-notifier.js should allow sending of completion emails regardless of test name https://bugs.webkit.org/show_bug.cgi?id=221712 Patch by Roy Reapor <rreapor@apple.com> on 2021-02-12 Reviewed by Dewei Zhu. Rule `platforms` and `tests` can be undefined, an empty array, or an array of strings. Undefined will match everything. Empty array will match nothing. Array of strings will match items in the array. Rule will not match if either `tests` or `platforms` is an empty array. * tools/js/analysis-results-notifier.js: (AnalysisResultsNotifier._validateRules.isUnderfinedOrEmptyArrayOrArrayOfStrings): - `platforms` and `tests` can now be undefined or an empty array officially (AnalysisResultsNotifier._validateRules): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) - both rule `platforms` and `tests` must pass `isUnderfinedOrEmptyArrayOrArrayOfStrings()`. previously, rules like `{tests: [1, 3], platforms: ['speedometer']}` passes validation. (AnalysisResultsNotifier._applyUpdate): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) (AnalysisResultsNotifier._validateRules.isNonemptyArrayOfStrings): Deleted. * unit-tests/analysis-results-notifier-tests.js: - added a bunch of unittests - specify the exact regex match for `assert.throws()` and `assert.doesNotThrow()` argument. Canonical link: https://commits.webkit.org/234049@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-12 22:29:04 +00:00
it('should match rule when platforms, tests, and userInitiated are undefined', () => {
const rule = {};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
});
it('should match rule when platforms and tests are undefined and userInitiated set to true', () => {
const rule = {userInitiated: true};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
});
it('should match rule when platforms and tests are undefined and userInitiated set to false', () => {
const rule = {userInitiated: false};
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
assert.ok(AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
});
it('should not match rule when platforms, and tests are empty arrays and userInitiated is undefined', () => {
const rule = {tests: [], platforms: []};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
});
it('should not match rule when platforms and tests are are empty arrays and userInitiated set to true', () => {
const rule = {tests: [], platforms: [], userInitiated: true};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
});
it('should not match rule when platforms and tests are empty and userInitiated set to false', () => {
const rule = {tests: [], platforms: [], userInitiated: false};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer, false, rule));
});
it('should not match rule when platforms is empty, tests match, userInitiated is undefined', () => {
const rule = {platforms: [], tests: [speedometer2, jetStream]};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, jetStream, false, rule));
});
it('should not match rule when tests is empty, platforms match, userInitiated is undefined', () => {
const rule = {tests: [], platforms: [trunkMacBook, trunkMacBookAir]};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, false, rule));
});
it('should not match rule when platforms is empty, tests match, userInitiated is true', () => {
const rule = {platforms: [], tests: [speedometer2, jetStream], userInitiated: true};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, jetStream, false, rule));
});
it('should not match rule when platforms is empty, tests match, userInitiated is false', () => {
const rule = {platforms: [], tests: [speedometer2, jetStream], userInitiated: false};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookPro, jetStream, true, rule));
});
it('should not match rule when tests is empty, platforms match, userInitiated is true', () => {
const rule = {tests: [], platforms: [trunkMacBook, trunkMacBookAir], userInitiated: true};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, speedometer, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, false, rule));
});
it('should not match rule when tests is empty, platforms match, userInitiated is false', () => {
const rule = {tests: [], platforms: [trunkMacBook, trunkMacBookAir], userInitiated: false};
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, speedometer2, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, speedometer, false, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBookAir, jetStream, true, rule));
assert.ok(!AnalysisResultsNotifier._matchesRule(trunkMacBook, jetStream, true, rule));
});
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
describe('_validateRules', () => {
perf.webkit.org/tools/js/analysis-results-notifier.js should allow sending of completion emails regardless of test name https://bugs.webkit.org/show_bug.cgi?id=221712 Patch by Roy Reapor <rreapor@apple.com> on 2021-02-12 Reviewed by Dewei Zhu. Rule `platforms` and `tests` can be undefined, an empty array, or an array of strings. Undefined will match everything. Empty array will match nothing. Array of strings will match items in the array. Rule will not match if either `tests` or `platforms` is an empty array. * tools/js/analysis-results-notifier.js: (AnalysisResultsNotifier._validateRules.isUnderfinedOrEmptyArrayOrArrayOfStrings): - `platforms` and `tests` can now be undefined or an empty array officially (AnalysisResultsNotifier._validateRules): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) - both rule `platforms` and `tests` must pass `isUnderfinedOrEmptyArrayOrArrayOfStrings()`. previously, rules like `{tests: [1, 3], platforms: ['speedometer']}` passes validation. (AnalysisResultsNotifier._applyUpdate): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) (AnalysisResultsNotifier._validateRules.isNonemptyArrayOfStrings): Deleted. * unit-tests/analysis-results-notifier-tests.js: - added a bunch of unittests - specify the exact regex match for `assert.throws()` and `assert.doesNotThrow()` argument. Canonical link: https://commits.webkit.org/234049@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-12 22:29:04 +00:00
it('should pass the validation for empty rule', () => {
assert.doesNotThrow(() => AnalysisResultsNotifier._validateRules([{}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should fail the validation for rule where `tests` is not an array of strings', () => {
assert.throws(() => AnalysisResultsNotifier._validateRules([{tests: [{}]}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should fail the validation for rule where `platforms` is not an array of strings', () => {
assert.throws(() => AnalysisResultsNotifier._validateRules([{platforms: [{}]}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should fail the validation for rule where `platforms` and `tests` are not an array of strings', () => {
assert.throws(() => AnalysisResultsNotifier._validateRules([{platforms: [{}], tests: [9, 1, 1]}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should fail the validation for rule where `platforms` or `tests` is not an array of strings', () => {
assert.throws(() => AnalysisResultsNotifier._validateRules([{platforms: ['System MacBookAir'], tests: [{}, 0]}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should fail the validation for rule where `platforms` or `tests` is not an array of strings', () => {
assert.throws(() => AnalysisResultsNotifier._validateRules([{platforms: ['Trunk MacBook', 5], tests: ['speedometer']}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
});
it('should pass the validation for rule where `tests` is an empty array', () => {
assert.doesNotThrow(() => AnalysisResultsNotifier._validateRules([{tests: []}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
perf.webkit.org/tools/js/analysis-results-notifier.js should allow sending of completion emails regardless of test name https://bugs.webkit.org/show_bug.cgi?id=221712 Patch by Roy Reapor <rreapor@apple.com> on 2021-02-12 Reviewed by Dewei Zhu. Rule `platforms` and `tests` can be undefined, an empty array, or an array of strings. Undefined will match everything. Empty array will match nothing. Array of strings will match items in the array. Rule will not match if either `tests` or `platforms` is an empty array. * tools/js/analysis-results-notifier.js: (AnalysisResultsNotifier._validateRules.isUnderfinedOrEmptyArrayOrArrayOfStrings): - `platforms` and `tests` can now be undefined or an empty array officially (AnalysisResultsNotifier._validateRules): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) - both rule `platforms` and `tests` must pass `isUnderfinedOrEmptyArrayOrArrayOfStrings()`. previously, rules like `{tests: [1, 3], platforms: ['speedometer']}` passes validation. (AnalysisResultsNotifier._applyUpdate): - switched to `assert.ok()`. `console.assert()` no longer throws since node v10 (https://github.com/facebook/jest/issues/5634) (AnalysisResultsNotifier._validateRules.isNonemptyArrayOfStrings): Deleted. * unit-tests/analysis-results-notifier-tests.js: - added a bunch of unittests - specify the exact regex match for `assert.throws()` and `assert.doesNotThrow()` argument. Canonical link: https://commits.webkit.org/234049@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@272813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-02-12 22:29:04 +00:00
it('should pass the validation for rule where `platforms` is an empty arrays', () => {
assert.doesNotThrow(() => AnalysisResultsNotifier._validateRules([{platforms: []}]), /AssertionError \[ERR_ASSERTION\]: Either tests or platforms must be an undefined, empty array, or an array of strings/);
Added sending notification feature when test group finishes. https://bugs.webkit.org/show_bug.cgi?id=184340 Reviewed by Ryosuke Niwa. Added 'testgroup_needs_notification' filed to 'analysis_test_group' table to indicate whether a test group has a pending notification. Added 'testgroup_notification_sent_at' to record the last notification sent time. SQL queries to update existing database are: 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_needs_notification boolean NOT NULL DEFAULT FALSE;' 'ALTER TABLE analysis_test_groups ADD COLUMN testgroup_notification_sent_at timestamp DEFAULT NULL;' Updated 'run-analysis' script to be able to send notification when test group finishes. Added 'Notify on completion' checkbox while creating/retrying/bisecting a test group. * browser-tests/test-group-form-tests.js: Updated existing tests and added a new test. * browser-tests/test-group-result-page-tests.js: Added unit tests for TestGroupResultPage. * init-database.sql: Added 'testgroup_needs_notification' filed to 'analysis_test_group' table. * public/api/test-groups.php: Added '/api/test-groups/ready-for-notification' API to 'test-group' to show all test groups that need to send notification. Only the ones with 'completed', 'failed' or 'cancelled' status and its 'testgroup_needs_notification' is true will be returned by this API. * public/include/build-requests-fetcher.php: Added 'fetch_requests_for_groups' to return test groups with given ids. * public/include/commit-sets-helpers.php: Updated the logic to support setting 'testgroup_needs_notification' while create an analysis_test_groups. * public/privileged-api/create-analysis-task.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/create-test-group.php: Updated the logic to support setting 'testgroup_needs_notification'. * public/privileged-api/update-test-group.php: Updated the logic to support updating 'testgroup_needs_notification'. Extended this API to allow authentication both from CSRF token and slave. * public/v3/components/custom-configuration-test-group-form.js: (CustomConfigurationTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. * public/v3/components/customizable-test-group-form.js: (CustomizableTestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (CustomizableTestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/components/test-group-form.js: (TestGroupForm): Added '_notifyOnCompletion' instance variable. (TestGroupForm.prototype.didConstructShadowTree): Added 'onchange' event for notify on completion checkbox. (TestGroupForm.prototype.startTesting): Pass 'notifyOnCompletion' information which represents 'testgroup_needs_notification' from API perspective. (TestGroupForm.cssTemplate): Added space between 'Notify on completion' checkbox and test group iteration selection list. * public/v3/models/analysis-results.js: Export 'AnalysisResults'. (AnalysisResults.fetch): Update API path to use absolute url. (AnalysisResults): * public/v3/models/analysis-task.js: (AnalysisTask.async.create): Extend this function to take notifyOnCompletion as argument which will be used as 'needsNotification' to send to server. (AnalysisTask): * public/v3/models/test-group.js: (TestGroup): Added '_needsNotification' field. (TestGroup.prototype.updateSingleton): Added logic to update '_needsNotification' field. (TestGroup.prototype.needsNotification): Returns '_needsNotification' field. (TestGroup.prototype.author): Returns author information. (TestGroup.prototype.async.didSendNotification): API that updates 'testgroup_needs_notification' to true. (TestGroup.prototype.async.fetchTask): API to fetch the task when it has not been fetched. (TestGroup.createWithTask): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createWithCustomConfiguration): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.createAndRefetchTestGroups): Updated this function to accept 'notifyOnCompletion' which will be used as 'needsNotification' to send to server. (TestGroup.fetchAllWithNotificationReady): New function that invokes '/api/test-groups/ready-for-notification'. * public/v3/pages/analysis-task-page.js: Update logic to 'notifyOnCompletion' around (AnalysisTaskChartPane.prototype.didConstructShadowTree): (AnalysisTaskResultsPane.prototype.didConstructShadowTree): (AnalysisTaskTestGroupPane.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype.didConstructShadowTree): (AnalysisTaskPage.prototype._retryCurrentTestGroup): (AnalysisTaskPage.prototype.async._bisectCurrentTestGroup): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList.set const): (AnalysisTaskPage.prototype._createTestGroupAfterVerifyingCommitSetList): (AnalysisTaskPage.prototype._createCustomTestGroup): * public/v3/pages/chart-pane.js: Added 'Notify on completion' checkbox. (ChartPane.prototype.didConstructShadowTree): (ChartPane.prototype.async._analyzeRange): * public/v3/pages/create-analysis-task-page.js: Adapted API change. (CreateAnalysisTaskPage.prototype._createAnalysisTaskWithGroup): * server-tests/api-test-groups.js: Added tests for '/api/test-groups/ready-for-notification'. * server-tests/privileged-api-create-analysis-task-tests.js: Updated tests to adapt this change. Added new tests. * server-tests/privileged-api-create-test-group-tests.js: Added new tests. * server-tests/privileged-api-update-test-group-tests.js: Added unit test for 'update-test-group' API. * server-tests/resources/mock-data.js: addMockData should set 'testgroup_needs_notification' to be true. * server-tests/tools-sync-buildbot-integration-tests.js: Updated tests to adapt this change. (async.createTestGroupWihPatch): (createTestGroupWihOwnedCommit): * tools/js/analysis-results-notifier.js: Added notifier to send notification for completed test groups. (AnalysisResultsNotifier): (AnalysisResultsNotifier.prototype.async.sendNotificationsForTestGroups): (AnalysisResultsNotifier.prototype._sendNotification): Invoke remote API to send notification. (AnalysisResultsNotifier.prototype._constructMessageByRules): (AnalysisResultsNotifier._matchesRule): (AnalysisResultsNotifier._applyUpdate): (AnalysisResultsNotifier.async._messageForTestGroup): Build html as message body for a test group. (AnalysisResultsNotifier._URLForAnalysisTask): Returns URL for an analysis task. (AnalysisResultsNotifier._instantiateNotificationTemplate): * tools/js/test-group-result-page.js: Added 'TestGroupResultPage' and 'BarGraph' to show test group result. (TestGroupResultPage): (TestGroupResultPage.prototype.async.setTestGroup): (TestGroupResultPage._urlForAnalysisTask): (TestGroupResultPage.prototype._URLForAnalysisTask): (TestGroupResultPage.prototype.constructTables): (TestGroupResultPage.prototype._constructTableForMetric): (TestGroupResultPage.): (TestGroupResultPage.prototype.get pageContent): (TestGroupResultPage.prototype.get styleTemplate): (BarGraph): (BarGraph.prototype.setWidth): (BarGraph.prototype._constructBarGraph): (BarGraph.prototype.get pageContent): (BarGraph.prototype.get styleTemplate): * tools/js/measurement-set-analyzer.js: Adapted 'AnalysisTask.create' change. (MeasurementSetAnalyzer.prototype.async._analyzeMeasurementSet): (MeasurementSetAnalyzer): * tools/js/v3-models.js: * tools/run-analysis.js: Added the logic that sends notification for completed test groups. (main): (async.analysisLoop): * unit-tests/analysis-task-tests.js: * unit-tests/analysis-results-notifier-tests.js: Added a unit test for 'AnalysisResultsNotifier' and 'NotificationService'. * unit-tests/measurement-set-analyzer-tests.js: Updated unit tests per this change. * unit-tests/test-groups-tests.js: Added unit tests for 'TestGroup.needsNotification'. * unit-tests/resources/mock-remote-api.js: Only set 'privilegedAPI' when it exits. Canonical link: https://commits.webkit.org/201783@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:44:28 +00:00
});
it('should pass the validation for if a rule only has tests specified', () => {
AnalysisResultsNotifier._validateRules([{tests: ['speedometer']}]);
});
it('should pass the validation for if a rule only has platforms specified', () => {
AnalysisResultsNotifier._validateRules([{platforms: ['Trunk MacBook']}]);
});
it('should pass the validation for if a rule has both tests and platforms specified', () => {
AnalysisResultsNotifier._validateRules([{tests: ['speedometer'], platforms: ['Trunk MacBook']}]);
});
});
describe('_applyUpdate', () => {
it('should set value directly if key does not exist in another object', () => {
const merged = AnalysisResultsNotifier._applyUpdate({a: 1}, {b: 2});
assert.deepEqual(merged, {a: 1, b: 2});
});
it('should concatenate arrays if both are array', () => {
const merged = AnalysisResultsNotifier._applyUpdate({a: [1]}, {a: [2]});
assert.deepEqual(merged, {a: [1, 2]});
});
it('should add to the array if only one side is array', () => {
const merged = AnalysisResultsNotifier._applyUpdate({a: [1], b: 1}, {a: 2, b: [2]});
assert.deepEqual(merged, {a: [1, 2], b: [1, 2]});
});
it('should merge recursively', () => {
const merged = AnalysisResultsNotifier._applyUpdate({a: {b: 1}}, {a: {b: [2]}});
assert.deepEqual(merged, {a: {b: [1, 2]}});
});
it('should merge values into array if one of value with same key is one of follow primitive types: number, string and boolean', () => {
const merged = AnalysisResultsNotifier._applyUpdate({a: 1, b: "a", c: 1, d: true, e: {}}, {a: 2, b: "b", c: "b", d: 2, e: 1});
assert.deepEqual(merged, {a: [1, 2], b: ["a", "b"], c: [1, "b"], d: [true, 2], e: [{}, 1]});
});
});
describe('_sendNotification', () => {
beforeEach(() => {
MockRemoteAPI.reset('http://send-notification.webkit.org/');
});
it('send a notification successfully', async () => {
const notifier = new AnalysisResultsNotifier(null, null, [{tests: ['a']}], MockRemoteAPI, 'send-notification');
const promise = notifier._sendNotification('test');
assert.equal(MockRemoteAPI.requests.length, 1);
const request = MockRemoteAPI.requests[0];
assert.equal(request.data, 'test');
assert.equal(request.url, 'send-notification');
assert.equal(request.method, 'POST');
request.resolve('ok');
const result = await promise;
assert.equal(result, 'ok');
});
it('should fail if notification request gets rejected', async () => {
const notifier = new AnalysisResultsNotifier(null, null, [{tests: ['a']}], MockRemoteAPI, 'send-notification');
const promise = notifier._sendNotification('test');
assert.equal(MockRemoteAPI.requests.length, 1);
const request = MockRemoteAPI.requests[0];
assert.equal(request.data, 'test');
assert.equal(request.url, 'send-notification');
assert.equal(request.method, 'POST');
request.reject('unavailable');
assertThrows('unavailable', () => promise);
});
});
});