Skip to content

Commit

Permalink
Merge pull request #30 from Kpoke/fix/test_max_connections
Browse files Browse the repository at this point in the history
fix/test max connections
  • Loading branch information
Kpoke committed Jul 10, 2022
2 parents dd9af87 + c89625e commit 6bdb929
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions api-tests/db-max-connection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` });
const log = require('loglevel');
require('../server/setup');
const request = require('supertest'); // eslint-disable-line
const server = require('../server/app');

(async () => {
for (let i = 0; i < 1000; i += 1) {
await request(server).get(`/stakeholders`);
log.info(`request ${i + 1}`);
}
})();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"seed": "knex seed:run",
"proxy": "http://localhost:3001/",
"prepare": "husky install",
"seed-dev": "NODE_ENV=development knex seed:run"
"seed-dev": "NODE_ENV=development knex seed:run",
"db-pool-test": "NODE_ENV=development node ./api-tests/db-max-connection-test.js"
},
"keywords": [
"ecology"
Expand Down
21 changes: 10 additions & 11 deletions server/app.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const request = require('supertest');
const { expect } = require('chai');
const server = require("./app");
const server = require('./app');


describe("", () => {

it("Test header: content-type: application/json", async () => {
const res = await request(server)
.get('/');
describe('', () => {
it('Test header: content-type: application/json', async () => {
const res = await request(server).get('/');
expect(res.statusCode).eq(200);
});

it("Test header: content-type: application/json", async () => {
const res = await request(server)
.post('/');
it('Test header: content-type: application/json', async () => {
const res = await request(server).post('/');

expect(res.statusCode).eq(415);
expect(res.body).property("message").match(/application.json/);
expect(res.body)
.property('message')
.match(/application.json/);
});
});
2 changes: 1 addition & 1 deletion server/database/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const knexConfig = {
client: 'pg',
debug: process.env.NODE_LOG_LEVEL === 'debug',
connection,
pool: { min: 0, max: 20 },
pool: { min: 0, max: 10 },
};

log.debug(process.env.DATABASE_SCHEMA);
Expand Down
10 changes: 5 additions & 5 deletions server/setup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* A file to setup some global setting, like log level
*/
const log = require("loglevel");

if(process.env.NODE_LOG_LEVEL){
const log = require('loglevel');

if (process.env.NODE_LOG_LEVEL) {
log.setDefaultLevel(process.env.NODE_LOG_LEVEL);
}else{
log.setDefaultLevel("info");
} else {
log.setDefaultLevel('info');
}

0 comments on commit 6bdb929

Please sign in to comment.