From b32773f3a841ba85f61240d617e11765a1c05fba Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 12:46:07 -0700 Subject: [PATCH 1/7] chore: refactor server test --- appengine/cloudsql/package.json | 4 +++- appengine/cloudsql/server.js | 4 ++-- appengine/cloudsql/test/serverListening.test.js | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 appengine/cloudsql/test/serverListening.test.js diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 80c2b7287f..6083837530 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -21,6 +21,7 @@ "test": "npm -- run all-test" }, "dependencies": { + "chai": "^4.2.0", "express": "^4.16.4", "knex": "^0.20.0", "mysql": "^2.16.0", @@ -31,7 +32,8 @@ "mocha": "^7.0.0", "proxyquire": "^2.1.0", "sinon": "^9.0.0", - "supertest": "^4.0.0" + "supertest": "^4.0.0", + "wait-port": "^0.2.7" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/appengine/cloudsql/server.js b/appengine/cloudsql/server.js index f0174ca3a1..20f0516bc3 100644 --- a/appengine/cloudsql/server.js +++ b/appengine/cloudsql/server.js @@ -109,10 +109,10 @@ app.get('/', async (req, res, next) => { }); const PORT = process.env.PORT || 8080; -app.listen(PORT, () => { +const server = app.listen(PORT, () => { console.log(`App listening on port ${PORT}`); console.log('Press Ctrl+C to quit.'); }); // [END gae_flex_mysql_app] -module.exports = app; +module.exports = {server, app}; diff --git a/appengine/cloudsql/test/serverListening.test.js b/appengine/cloudsql/test/serverListening.test.js new file mode 100644 index 0000000000..21330e681a --- /dev/null +++ b/appengine/cloudsql/test/serverListening.test.js @@ -0,0 +1,12 @@ +const {server} = require('../server.js'); +const waitPort = require('wait-port'); +const {expect} = require('chai'); + +describe('server listening', () => { + it('should be listening', async () => { + const isOpen = await waitPort({port: 8080}); + console.log("is open?"+await isOpen); + expect(await isOpen).to.be.true; + server.close(); + }) +}); \ No newline at end of file From 6d25fdaa100dec1d05eea725b5c43e6196473998 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 12:49:54 -0700 Subject: [PATCH 2/7] chore: change repo tools testing --- appengine/cloudsql/package.json | 3 +-- appengine/cloudsql/test/serverListening.test.js | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 6083837530..7e4f6e5746 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -15,7 +15,7 @@ "scripts": { "unit-test": "mocha test/*.test.js --timeout=60000", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", - "system-test": "repo-tools test app -- server.js", + "system-test": "mocha test/serverListening.test.js --timeout=60000", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", "test": "npm -- run all-test" @@ -28,7 +28,6 @@ "prompt": "^1.0.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.3.0", "mocha": "^7.0.0", "proxyquire": "^2.1.0", "sinon": "^9.0.0", diff --git a/appengine/cloudsql/test/serverListening.test.js b/appengine/cloudsql/test/serverListening.test.js index 21330e681a..814f02b551 100644 --- a/appengine/cloudsql/test/serverListening.test.js +++ b/appengine/cloudsql/test/serverListening.test.js @@ -5,8 +5,8 @@ const {expect} = require('chai'); describe('server listening', () => { it('should be listening', async () => { const isOpen = await waitPort({port: 8080}); - console.log("is open?"+await isOpen); + console.log(`is open?${await isOpen}`); expect(await isOpen).to.be.true; server.close(); - }) -}); \ No newline at end of file + }); +}); From 8d87a2c64fc2b9aa268140b74bf7038c6d18fc53 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 13:10:54 -0700 Subject: [PATCH 3/7] try removing timeout --- appengine/cloudsql/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 7e4f6e5746..19b23bcdd5 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -15,7 +15,7 @@ "scripts": { "unit-test": "mocha test/*.test.js --timeout=60000", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", - "system-test": "mocha test/serverListening.test.js --timeout=60000", + "system-test": "mocha test/serverListening.test.js --exit", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", "test": "npm -- run all-test" From ee6c6399e514b9897b50485561b5a57080e54743 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 13:22:13 -0700 Subject: [PATCH 4/7] test suite once --- appengine/cloudsql/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 19b23bcdd5..4db5b7b940 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -15,7 +15,6 @@ "scripts": { "unit-test": "mocha test/*.test.js --timeout=60000", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", - "system-test": "mocha test/serverListening.test.js --exit", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", "test": "npm -- run all-test" From 8505ea35d868c855f13a0f3740bae021ea82aa26 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 13:24:48 -0700 Subject: [PATCH 5/7] revert to including system test --- appengine/cloudsql/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 4db5b7b940..19b23bcdd5 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -15,6 +15,7 @@ "scripts": { "unit-test": "mocha test/*.test.js --timeout=60000", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", + "system-test": "mocha test/serverListening.test.js --exit", "system-test-proxy": "npm run start-proxy; npm run system-test", "all-test": "npm run unit-test && npm run system-test", "test": "npm -- run all-test" From d50a573eb4962bd3a1058ebc8a8947610a06c3ac Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 13:35:18 -0700 Subject: [PATCH 6/7] try separating out tests --- appengine/cloudsql/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json index 19b23bcdd5..9d26eb0d06 100644 --- a/appengine/cloudsql/package.json +++ b/appengine/cloudsql/package.json @@ -13,7 +13,7 @@ "node": ">=8.0.0" }, "scripts": { - "unit-test": "mocha test/*.test.js --timeout=60000", + "unit-test": "mocha test/createTables.test.js --timeout=60000 && mocha test/server.test.js", "start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &", "system-test": "mocha test/serverListening.test.js --exit", "system-test-proxy": "npm run start-proxy; npm run system-test", From d84a277eb370c19ab44e2d421d1d345479b36c17 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Tue, 31 Mar 2020 14:56:48 -0700 Subject: [PATCH 7/7] fix: failing test --- appengine/cloudsql/server.js | 4 ++-- appengine/cloudsql/test/serverListening.test.js | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/appengine/cloudsql/server.js b/appengine/cloudsql/server.js index 20f0516bc3..f0174ca3a1 100644 --- a/appengine/cloudsql/server.js +++ b/appengine/cloudsql/server.js @@ -109,10 +109,10 @@ app.get('/', async (req, res, next) => { }); const PORT = process.env.PORT || 8080; -const server = app.listen(PORT, () => { +app.listen(PORT, () => { console.log(`App listening on port ${PORT}`); console.log('Press Ctrl+C to quit.'); }); // [END gae_flex_mysql_app] -module.exports = {server, app}; +module.exports = app; diff --git a/appengine/cloudsql/test/serverListening.test.js b/appengine/cloudsql/test/serverListening.test.js index 814f02b551..53c2e52319 100644 --- a/appengine/cloudsql/test/serverListening.test.js +++ b/appengine/cloudsql/test/serverListening.test.js @@ -1,12 +1,10 @@ -const {server} = require('../server.js'); const waitPort = require('wait-port'); const {expect} = require('chai'); describe('server listening', () => { it('should be listening', async () => { + require('../server.js'); const isOpen = await waitPort({port: 8080}); - console.log(`is open?${await isOpen}`); - expect(await isOpen).to.be.true; - server.close(); + expect(isOpen).to.be.true; }); });