Skip to content

Commit

Permalink
fix: remove get-port
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 7, 2025
1 parent 2245ea4 commit 140d3ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion yarn-project/blob-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"@types/node": "^18.7.23",
"@types/source-map-support": "^0.5.10",
"@types/supertest": "^6.0.2",
"get-port": "^7.1.0",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
"supertest": "^7.0.0",
Expand Down
5 changes: 1 addition & 4 deletions yarn-project/blob-sink/src/client/http.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Blob } from '@aztec/foundation/blob';
import { Fr } from '@aztec/foundation/fields';

import getPort from 'get-port';

import { BlobSinkServer } from '../server/server.js';
import { runBlobSinkClientTests } from './blob-sink-client-tests.js';
import { HttpBlobSinkClient } from './http.js';

describe('HttpBlobSinkClient', () => {
runBlobSinkClientTests(async () => {
const port = await getPort();
const server = new BlobSinkServer({
port,
port: 0,
});
await server.start();

Expand Down
14 changes: 12 additions & 2 deletions yarn-project/blob-sink/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

import express, { type Express, type Request, type Response, json } from 'express';
import { type Server } from 'http';
import { AddressInfo } from 'net';
import { z } from 'zod';

import { type BlobStore, DiskBlobStore } from '../blobstore/index.js';
Expand All @@ -23,7 +24,7 @@ import { BlobSinkMetrics } from './metrics.js';
* await service.stop();
*/
export class BlobSinkServer {
public readonly port: number;
public port: number;

private app: Express;
private server: Server | null = null;
Expand Down Expand Up @@ -135,8 +136,17 @@ export class BlobSinkServer {
}

public start(): Promise<void> {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
this.server = this.app.listen(this.port, () => {
// Extract port from server address, allows setting address when
// server is started with port 0
const address = this.server?.address() as AddressInfo | null;
if (!address) {
this.log.error('Server address not found');
this.stop().then(() => reject(new Error('Server address not found')));
}

this.port = address!.port;
this.log.info(`Server is running on http://localhost:${this.port}`);
resolve();
});
Expand Down
1 change: 0 additions & 1 deletion yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ __metadata:
"@types/source-map-support": "npm:^0.5.10"
"@types/supertest": "npm:^6.0.2"
express: "npm:^4.21.1"
get-port: "npm:^7.1.0"
jest: "npm:^29.5.0"
jest-mock-extended: "npm:^3.0.3"
source-map-support: "npm:^0.5.21"
Expand Down

0 comments on commit 140d3ed

Please sign in to comment.