Skip to content

Commit f9f8b08

Browse files
authored
Merge pull request #189 from bitfinexcom/beta
Release version 4.3.1
2 parents 8466a98 + 99b1f17 commit f9f8b08

17 files changed

Lines changed: 284 additions & 188 deletions

.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recursive": true,
3+
"timeout": 10000,
4+
"exit": true
5+
}

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [4.3.1] - 2023-03-15
11+
12+
### Changed
13+
14+
- Improved the lookup of the free ports for the backend side of the app and fixes the issue: [#171](https://github.com/bitfinexcom/bfx-report-electron/issues/171). PRs: [bfx-report-electron#187](https://github.com/bitfinexcom/bfx-report-electron/pull/187), [bfx-report-ui#619](https://github.com/bitfinexcom/bfx-report-ui/pull/619)
15+
- Reworked `getUsers` call without auth params that are redundant for this public endpoint. PR: [bfx-report-ui#618](https://github.com/bitfinexcom/bfx-report-ui/pull/618)
16+
17+
### Fixed
18+
19+
- Fixed issues with some symbols representation in the `Symbol Filter` dropdown list. PR: [bfx-report-ui#617](https://github.com/bitfinexcom/bfx-report-ui/pull/617)
20+
1021
## [4.3.0] - 2023-03-01
1122

1223
### Added

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bfx-report-electron",
3-
"version": "4.3.0",
3+
"version": "4.3.1",
44
"repository": "https://github.com/bitfinexcom/bfx-report-electron",
55
"description": "Reporting tool",
66
"author": "bitfinex.com",
@@ -24,7 +24,7 @@
2424
"electron-serve": "1.1.0",
2525
"electron-updater": "5.0.4",
2626
"extract-zip": "2.0.1",
27-
"find-free-port": "2.0.0",
27+
"get-port": "6.1.2",
2828
"github-markdown-css": "5.1.0",
2929
"grenache-grape": "git+https://github.com/bitfinexcom/grenache-grape.git",
3030
"js-yaml": "4.1.0",
@@ -39,6 +39,7 @@
3939
"app-builder-bin": "4.1.0",
4040
"electron": "13.6.9",
4141
"electron-builder": "23.0.9",
42+
"mocha": "10.2.0",
4243
"standard": "16.0.4"
4344
},
4445
"standard": {
@@ -51,7 +52,8 @@
5152
},
5253
"scripts": {
5354
"start": "export NODE_ENV=development&&export DEBUG=*&&electron .",
54-
"test": "standard",
55+
"test": "standard && npm run unit",
56+
"unit": "export NODE_ENV=test && mocha './src/**/__test__/*.spec.js' --config .mocharc.json",
5557
"setup": "./scripts/setup.sh",
5658
"launch": "./scripts/launch.sh",
5759
"sync-repo": "./scripts/sync-repo.sh"

scripts/build-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if [ $# == 0 ]; then
8080
exit 1
8181
fi
8282

83-
while getopts "lwmsdph" opt; do
83+
while getopts "lwmsduph" opt; do
8484
case "${opt}" in
8585
l) buildLinux=1;;
8686
w) buildWin=1;;

scripts/launch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if [ $# == 0 ]; then
5555
exit 1
5656
fi
5757

58-
while getopts "alwmrosdph" opt; do
58+
while getopts "alwmrosduph" opt; do
5959
case "${opt}" in
6060
a)
6161
buildLinux=1

scripts/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function usage {
5555
${COLOR_NORMAL}" 1>&2
5656
}
5757

58-
while getopts "rosdh" opt; do
58+
while getopts "rosduh" opt; do
5959
case "${opt}" in
6060
r) syncRepo=1;;
6161
o) syncSubModules=1;;

server.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ process.env.NODE_CONFIG_DIR = pathToExpressConfDir
2727

2828
const env = { ...process.env }
2929
const {
30-
getDefaultPorts,
31-
getFreePort,
3230
serializeError
3331
} = require('./src/helpers')
3432

3533
const {
36-
RunningExpressOnPortError,
3734
WrongPathToUserDataError,
3835
WrongPathToUserCsvError,
3936
WrongSecretKeyError
@@ -101,6 +98,13 @@ const allowedProcessStatesSet = _getAllowedStatesSet({
10198
const pathToUserCsv = process.env.PATH_TO_USER_CSV
10299
const schedulerRule = process.env.SCHEDULER_RULE
103100
const secretKey = process.env.SECRET_KEY
101+
const grape1DhtPort = process.env.GRAPE_1DHT_PORT
102+
const grape1ApiPort = process.env.GRAPE_1API_PORT
103+
const grape2DhtPort = process.env.GRAPE_2DHT_PORT
104+
const grape2ApiPort = process.env.GRAPE_2API_PORT
105+
const workerApiPort = process.env.WORKER_API_PORT
106+
const workerWsPort = process.env.WORKER_WS_PORT
107+
const expressApiPort = process.env.EXPRESS_API_PORT
104108

105109
if (!secretKey) {
106110
throw new WrongSecretKeyError()
@@ -112,30 +116,11 @@ const allowedProcessStatesSet = _getAllowedStatesSet({
112116
throw new WrongPathToUserCsvError()
113117
}
114118

115-
const defaultPorts = getDefaultPorts()
116-
const {
117-
grape1DhtPort,
118-
grape1ApiPort,
119-
grape2DhtPort,
120-
grape2ApiPort,
121-
workerApiPort,
122-
workerWsPort,
123-
expressApiPort
124-
} = await getFreePort(defaultPorts)
125119
const grape = `http://127.0.0.1:${grape2ApiPort}`
126120

127121
confFacsGrc.p0.grape = grape
128122
confFacsGrc.p1.grape = grape
129123

130-
if (defaultPorts.expressApiPort !== expressApiPort) {
131-
process.send({
132-
state: 'error:express-port-required',
133-
err: serializeError(new RunningExpressOnPortError())
134-
})
135-
136-
return
137-
}
138-
139124
process.env.NODE_CONFIG = JSON.stringify({
140125
app: {
141126
port: expressApiPort

src/errors/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ class InvalidFolderPathError extends BaseError {
4141
}
4242
}
4343

44-
class RunningExpressOnPortError extends BaseError {
45-
constructor (message = 'ERR_EXPRESS_PORT_IS_REQUIRED') {
46-
super(message)
47-
}
48-
}
49-
5044
class IpcMessageError extends BaseError {
5145
constructor (message = 'ERR_IPC_MESSAGE') {
5246
super(message)
@@ -120,7 +114,6 @@ module.exports = {
120114
DbImportingError,
121115
DbRemovingError,
122116
InvalidFolderPathError,
123-
RunningExpressOnPortError,
124117
IpcMessageError,
125118
AppInitializationError,
126119
FreePortError,

src/helpers/__test__/ports.spec.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
'use strict'
2+
3+
const { isObject } = require('lodash')
4+
const assert = require('assert').strict
5+
const { Server } = require('net')
6+
const DHT = require('bittorrent-dht')
7+
8+
const {
9+
getFreePort,
10+
isDHTPort,
11+
getMaxPort,
12+
getDefaultPorts,
13+
getPortRangesForLookingUp
14+
} = require('../ports')
15+
const { getServerPromise } = require('../utils')
16+
17+
const checkAssertions = (res) => {
18+
assert.ok(isObject(res))
19+
assert.ok(
20+
[
21+
'grape1DhtPort',
22+
'grape1ApiPort',
23+
'grape2DhtPort',
24+
'grape2ApiPort',
25+
'workerApiPort',
26+
'workerWsPort',
27+
'expressApiPort'
28+
].every((key) => Number.isFinite(res[key]))
29+
)
30+
31+
const maxPort = getMaxPort()
32+
const defaultPorts = getDefaultPorts()
33+
const ranges = getPortRangesForLookingUp()
34+
35+
for (const [name, port] of Object.entries(res)) {
36+
assert.ok(port >= defaultPorts[name])
37+
assert.ok(port <= maxPort)
38+
39+
const errors = []
40+
41+
for (const { from, to } of ranges) {
42+
try {
43+
assert.ok(port >= from)
44+
assert.ok(port <= to)
45+
} catch (err) {
46+
errors.push(err)
47+
}
48+
}
49+
50+
if (errors.length >= ranges.length) {
51+
throw errors[0]
52+
}
53+
}
54+
}
55+
56+
describe('getFreePort helper', () => {
57+
it('it should lookup free ports', async function () {
58+
const res = await getFreePort()
59+
60+
checkAssertions(res)
61+
})
62+
63+
it('it should lookup free ports while the previous 3 lookups have been used', async function () {
64+
const dhts = []
65+
const srvs = []
66+
67+
for (let i = 0; i < 3; i += 1) {
68+
const newPorts = await getFreePort()
69+
70+
for (const [newName, newPort] of Object.entries(newPorts)) {
71+
if (isDHTPort(newName)) {
72+
const dht = new DHT()
73+
dhts.push(dht)
74+
75+
await getServerPromise(dht, newPort)
76+
77+
continue
78+
}
79+
80+
const srv = new Server()
81+
srv.unref()
82+
srvs.push(srv)
83+
84+
await getServerPromise(srv, newPort)
85+
}
86+
}
87+
88+
const res = await getFreePort()
89+
90+
checkAssertions(res)
91+
92+
const promises = []
93+
94+
for (const dht of dhts) {
95+
promises.push(new Promise((resolve) => dht.destroy(resolve)))
96+
}
97+
for (const srv of srvs) {
98+
promises.push(new Promise((resolve) => srv.close(resolve)))
99+
}
100+
101+
await Promise.all(promises)
102+
})
103+
})

0 commit comments

Comments
 (0)