Skip to content

Commit

Permalink
fix: always use free port for ZMQ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Aug 27, 2019
1 parent e874595 commit 8eb6984
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"test:int:watch": "jest test/integration --runInBand --watch",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"prepublishOnly": "npm run compile",

"python:install": "pip install -r tools/requirements.txt",
"python:lint": "pylint tools/*.py docker/*.py"
},
Expand Down Expand Up @@ -91,6 +90,7 @@
"@types/zeromq": "^4.6.2",
"concurrently": "^4.1.2",
"conventional-changelog": "^3.1.10",
"get-port": "^5.0.0",
"grpc-tools": "^1.8.0",
"grpc_tools_node_protoc_ts": "^2.5.4",
"jest": "^24.9.0",
Expand Down
14 changes: 11 additions & 3 deletions test/unit/chain/ZmqClient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getPort from 'get-port';
import zmq, { Socket } from 'zeromq';
import { randomBytes } from 'crypto';
import { OutputType } from 'boltz-core';
Expand Down Expand Up @@ -37,10 +38,10 @@ describe('ZmqClient', () => {
const chainClient = new FakedChainClient();

// ZMQ publisher
const rawTx = new ZmqPublisher(3000, filters.rawTx);
let rawTx: ZmqPublisher;

const rawBlock = new ZmqPublisher(3001, filters.rawBlock);
const hashBlock = new ZmqPublisher(3002, filters.hashBlock);
let rawBlock: ZmqPublisher;
let hashBlock: ZmqPublisher;

const sendHashBlock = (height?: number, orphan = false) => {
const { hash } = chainClient.generateBlock(height, orphan);
Expand Down Expand Up @@ -75,6 +76,13 @@ describe('ZmqClient', () => {
chainClient.getRawTransactionVerbose,
);

beforeAll(async () => {
rawTx = new ZmqPublisher(await getPort(), filters.rawTx);

rawBlock = new ZmqPublisher(await getPort(), filters.rawBlock);
hashBlock = new ZmqPublisher(await getPort(), filters.hashBlock);
});

test('should not init without needed subscriptions', async () => {
const rejectZmqClient = new ZmqClient(
'BTC',
Expand Down

0 comments on commit 8eb6984

Please sign in to comment.