Skip to content

Commit 644060e

Browse files
Display an error message at start of test:sequential if json2capnp is not running
This will display that error message: ================================================================================ ERROR: json2capnp service is not running! ================================================================================ The sequential tests require the json2capnp rust server to be started. To start the service, run the following commands: cd services/json2capnp cargo run 2000 ../../projects/test/test_cache/test Or in a single command from the project root: (cd services/json2capnp && cargo run 2000 ../../projects/test/test_cache/test) Expected service location: localhost:2000 ================================================================================
1 parent 5660ee9 commit 644060e

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

packages/transition-backend/jest.sequential.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ const baseConfig = require('../../tests/jest.config.base');
1616
// Run the db and integration tests
1717
module.exports = {
1818
...baseConfig,
19-
'testRegex': ['(/__tests__/.*(db\\.test)\\.(jsx?|tsx?))$','(/__tests__/.*(integration\\.test)\\.(jsx?|tsx?))$']
19+
'testRegex': ['(/__tests__/.*(db\\.test)\\.(jsx?|tsx?))$','(/__tests__/.*(integration\\.test)\\.(jsx?|tsx?))$'],
20+
globalSetup: '<rootDir>/jest.sequential.setup.js'
2021
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2022, Polytechnique Montreal and contributors
3+
*
4+
* This file is licensed under the MIT License.
5+
* License text available at https://opensource.org/licenses/MIT
6+
*/
7+
8+
/**
9+
* Global setup for sequential tests that require the json2capnp service
10+
*/
11+
12+
function displayJson2CapnpError(host, port, reason = 'not running') {
13+
console.error('\n' + '='.repeat(80));
14+
console.error(`ERROR: json2capnp service is ${reason}!`);
15+
console.error('='.repeat(80));
16+
console.error('\nThe sequential tests require the json2capnp rust server to be started.');
17+
console.error('\nTo start the service, run the following commands:');
18+
console.error(' cd services/json2capnp');
19+
console.error(' cargo run 2000 ../../projects/test/test_cache/test');
20+
console.error('\nOr in a single command from the project root:');
21+
console.error(' (cd services/json2capnp && cargo run 2000 ../../projects/test/test_cache/test)');
22+
console.error(`\nExpected service location: ${host}:${port}`);
23+
console.error('\n' + '='.repeat(80) + '\n');
24+
}
25+
26+
module.exports = async () => {
27+
const http = require('http');
28+
const Preferences = require('chaire-lib-common/lib/config/Preferences').default;
29+
30+
// Get json2capnp configuration
31+
const json2CapnpConfig = Preferences.get('json2Capnp', {
32+
host: 'http://localhost',
33+
port: 2000
34+
});
35+
36+
const host = json2CapnpConfig.host.replace(/^https?:\/\//, '');
37+
const port = json2CapnpConfig.port;
38+
39+
console.log(`\nChecking if json2capnp service is running at ${host}:${port}...`);
40+
41+
return new Promise((resolve, reject) => {
42+
const request = http.get({
43+
hostname: host,
44+
port: port,
45+
path: '/',
46+
timeout: 2000
47+
}, (res) => {
48+
console.log('✓ json2capnp service is running');
49+
resolve();
50+
});
51+
52+
request.on('error', (err) => {
53+
displayJson2CapnpError(host, port, 'not running');
54+
reject(new Error(`json2capnp service is not available at ${host}:${port}`));
55+
});
56+
57+
request.on('timeout', () => {
58+
request.destroy();
59+
displayJson2CapnpError(host, port, 'not responding (timeout)');
60+
reject(new Error(`json2capnp service connection timeout at ${host}:${port}`));
61+
});
62+
});
63+
};

packages/transition-backend/src/api/services.socketRoutes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default function (socket: EventEmitter, userId?: number) {
140140
options: TransitMapCalculationOptions,
141141
callback: (status: Status.Status<TransitAccessibilityMapWithPolygonResult>) => void
142142
) => {
143+
console.time('accessibiliyMap.calculateWithPolygons');
143144
try {
144145
const resultsWithPolygon = await TransitAccessibilityMapCalculator.calculateWithPolygons(
145146
routingAttributes,
@@ -154,6 +155,7 @@ export default function (socket: EventEmitter, userId?: number) {
154155
)
155156
);
156157
}
158+
console.timeEnd('accessibiliyMap.calculateWithPolygons');
157159
}
158160
);
159161

0 commit comments

Comments
 (0)