Add mocha server tests for /api/build-requests
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Mar 2016 20:17:01 +0000 (20:17 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Mar 2016 20:17:01 +0000 (20:17 +0000)
commita23fd4fc9dac3c9fc070115ad08e76c5c642a6d4
treeb9a1ec648e414f8978dad3af2e04ae7b97495c10
parent8b155d79f8d34b395bf0ec96a7586863c710b761
Add mocha server tests for /api/build-requests
https://bugs.webkit.org/show_bug.cgi?id=155831

Reviewed by Chris Dumez.

Added the new mocha.js based server-tests for /api/build-requests. The new harness automatically:
 - starts a new Apache instance
 - switches the database during testing via setting an environmental variable
 - backups and restores public/data directory during testing

As a result, developer no longer has to manually setup Apache, edit config.json manually to use
a testing database, or run /api/manifest.php to re-generate the manifest file after testing.

This patch also makes ID resolution optional on /api/build-requests so that v3 model based syncing
scripts can re-use the same code as the v3 UI to process the JSON. tools/sync-with-buildbot.py has
been modified to use this option (useLegacyIdResolution).

* config.json: Added configurations for the test httpd server.
* init-database.sql: Don't error when tables and types don't exist (when database is empty).
* public/api/build-requests.php:
(main): Made the ID resolution optional with useLegacyIdResolution. Also removed "updates" from the
results JSON since it's never used.
* public/include/build-requests-fetcher.php:
(BuildRequestsFetcher::__construct):
(BuildRequestsFetcher::fetch_roots_for_set_if_needed): Fixed the bug that we would include the same
commit multiple times for each root set.
* public/include/db.php:
(config): If present, use ORG_WEBKIT_PERF_CONFIG_PATH instead of Websites/perf.webkit.org/config.json.
* server-tests: Added.
* server-tests/api-build-requests-tests.js: Added. Tests for /api/build-requests.
(.addMockData):
* server-tests/resources: Added.
* server-tests/resources/test-server.conf: Added. Apache configuration file for testing.
* server-tests/resources/test-server.js: Added.
(TestSever): Added.
(TestSever.prototype.start): Added.
(TestSever.prototype.stop): Added.
(TestSever.prototype.remoteAPI): Added. Configures RemoteAPI to be used with the test sever.
(TestSever.prototype.database): Added. Returns Database configured to use the test database.
(TestSever.prototype._constructTestConfig): Creates config.json for testing. The file is generated by
_start and db.php's config() reads it from the environmental variable: ORG_WEBKIT_PERF_CONFIG_PATH.
(TestSever.prototype._ensureDataDirectory): Renames public/data to public/original-data if exists,
and creates a new empty public/data.
(TestSever.prototype._restoreDataDirectory): Deletes public/data and renames public/original-data
back to public/data.
(TestSever.prototype._ensureTestDatabase): Drops the test database if exists and creates a new one.
(TestSever.prototype.initDatabase): Run init-database.sql to start each test with a consistent state.
(TestSever.prototype._executePgsqlCommand): Executes a postgres command line tool such as psql.
(TestSever.prototype._determinePgsqlDirectory): Finds the directory that contains psql.
(TestSever.prototype._startApache): Starts an Apache instance for testing.
(TestSever.prototype._stopApache): Stops the Apache instance for testing.
(TestSever.prototype._waitForPid): Waits for the Apache pid file to appear or disappear.
(before): Start the test server at the beginning.
(beforeEach): Re-initialize all tables before each test.
(after): Stop the test server at the end.
* tools/js/config.js:
(Config.prototype.path):
(Config.prototype.serverRoot): Added. The path to Websites/perf.webkit.org/public/.
(Config.prototype.pathFromRoot): Added. Resolves a path from Websites/perf.webkit.org.
* tools/js/database.js:
(Database): Now optionally takes the database name to use a different database during testing.
(Database.prototype.connect):
(Database.prototype.query): Added.
(Database.prototype.insert): Added.
(tableToPrefixMap): Maps table name to its prefix. Used by Database.insert.
* tools/js/remote.js: Added.
(RemoteAPI): Added. This is node.js equivalent of RemoteAPI in public/v3/remote.js.
(RemoteAPI.prototype.configure): Added.
(RemoteAPI.prototype.fetchJSON): Added.
(RemoteAPI.prototype.fetchJSONWithStatus): Added.
(RemoteAPI.prototype.sendHttpRequest): Added.
* tools/sync-with-buildbot.py:
(main): Use useLegacyIdResolution as this script relies on the legacy behavior.
* unit-tests/checkconfig.js: pg was never directly used in this test.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198642 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/config.json
Websites/perf.webkit.org/init-database.sql
Websites/perf.webkit.org/public/api/build-requests.php
Websites/perf.webkit.org/public/include/build-requests-fetcher.php
Websites/perf.webkit.org/public/include/db.php
Websites/perf.webkit.org/server-tests/api-build-requests-tests.js [new file with mode: 0644]
Websites/perf.webkit.org/server-tests/resources/test-server.conf [new file with mode: 0644]
Websites/perf.webkit.org/server-tests/resources/test-server.js [new file with mode: 0644]
Websites/perf.webkit.org/tools/js/config.js
Websites/perf.webkit.org/tools/js/database.js
Websites/perf.webkit.org/tools/js/remote.js [new file with mode: 0644]
Websites/perf.webkit.org/tools/sync-with-buildbot.py
Websites/perf.webkit.org/unit-tests/checkconfig.js