diff --git a/src/services/cogrpc/server.spec.ts b/src/services/cogrpc/server.spec.ts index 6893458d2..3e37b47a2 100644 --- a/src/services/cogrpc/server.spec.ts +++ b/src/services/cogrpc/server.spec.ts @@ -17,7 +17,7 @@ const makeServiceImplementationSpy = mockSpy( ); const mockServer = { addService: mockSpy(jest.fn()), - bindAsync: mockSpy(jest.fn(), () => Promise.resolve()), + bindAsync: mockSpy(jest.fn(), (_netloc, _credentials, cb) => cb()), start: mockSpy(jest.fn()), }; jest.mock('@grpc/grpc-js', () => { @@ -161,9 +161,8 @@ describe('runServer', () => { expect.anything(), expect.objectContaining({ statusMap: { - '': grpcHealthCheck.messages.HealthCheckResponse.ServingStatus.SERVING, - 'relaynet.cogrpc.CargoRelay': - grpcHealthCheck.messages.HealthCheckResponse.ServingStatus.SERVING, + '': grpcHealthCheck.servingStatus.SERVING, + 'relaynet.cogrpc.CargoRelay': grpcHealthCheck.servingStatus.SERVING, }, }), ); @@ -173,14 +172,18 @@ describe('runServer', () => { await runServer(); expect(mockServer.bindAsync).toBeCalledTimes(1); - expect(mockServer.bindAsync).toBeCalledWith('0.0.0.0:8080', expect.anything()); + expect(mockServer.bindAsync).toBeCalledWith( + '0.0.0.0:8080', + expect.anything(), + expect.anything(), + ); }); test('Failing to listen on specified port should result in error', async () => { - const bindError = new Error('Port is apparently taken') - mockServer.bindAsync.mockRejectedValue(bindError); + const bindError = new Error('Port is apparently taken'); + mockServer.bindAsync.mockImplementation((_netloc, _credentials, cb) => cb(bindError)); - await expect(() => runServer()).rejects.toEqual(bindError) + await expect(() => runServer()).rejects.toBe(bindError); }); test('Server should use TLS with a self-issued certificate', async () => { diff --git a/src/services/cogrpc/server.ts b/src/services/cogrpc/server.ts index a6cc47463..2df6e0fcf 100644 --- a/src/services/cogrpc/server.ts +++ b/src/services/cogrpc/server.ts @@ -1,7 +1,7 @@ import { KeyCertPair, Server, ServerCredentials } from '@grpc/grpc-js'; import { CargoRelayService } from '@relaycorp/cogrpc'; import { get as getEnvVar } from 'env-var'; -import grpcHealthCheck from 'grpc-js-health-check'; +import * as grpcHealthCheck from 'grpc-js-health-check'; import { Logger } from 'pino'; import * as selfsigned from 'selfsigned'; import { configureExitHandling } from '../../utilities/exitHandling'; @@ -46,15 +46,14 @@ export async function runServer(logger?: Logger): Promise { parcelStoreBucket, publicAddress, }); - server.addService(CargoRelayService, serviceImplementation); + server.addService(CargoRelayService, serviceImplementation as any); // TODO: Health checks should be probing backing services const healthCheckService = new grpcHealthCheck.Implementation({ - '': grpcHealthCheck.messages.HealthCheckResponse.ServingStatus.SERVING, - 'relaynet.cogrpc.CargoRelay': - grpcHealthCheck.messages.HealthCheckResponse.ServingStatus.SERVING, + '': grpcHealthCheck.servingStatus.SERVING, + 'relaynet.cogrpc.CargoRelay': grpcHealthCheck.servingStatus.SERVING, }); - server.addService(grpcHealthCheck.service, healthCheckService); + server.addService(grpcHealthCheck.service, healthCheckService as any); const certificate = await selfIssueCertificate(); await new Promise((resolve, reject) => { diff --git a/src/types/grpc-js-health-check.d.ts b/src/types/grpc-js-health-check.d.ts index 95718facb..4c891cbd2 100644 --- a/src/types/grpc-js-health-check.d.ts +++ b/src/types/grpc-js-health-check.d.ts @@ -6,12 +6,8 @@ declare module 'grpc-js-health-check' { constructor(map: { readonly [key: string]: string }); } - export const messages: { - readonly HealthCheckResponse: { - readonly ServingStatus: { - readonly NOT_SERVING: any; - readonly SERVING: any; - }; - }; + export const servingStatus: { + readonly NOT_SERVING: any; + readonly SERVING: any; }; }