From d932913419ea34f70011584ae1620d43911fdbf9 Mon Sep 17 00:00:00 2001 From: aikoven Date: Sat, 14 Oct 2023 13:49:51 +0200 Subject: [PATCH] chore: fix hanging and erroring tests --- .../src/index.test.ts | 13 +++--- .../src/index.test.ts | 12 +++--- .../nice-grpc-error-details/src/index.test.ts | 4 +- .../src/__tests__/bidiStreaming.ts | 18 ++++---- .../src/__tests__/clientStreaming.ts | 12 +++--- .../src/__tests__/context.ts | 4 +- .../src/__tests__/serverStreaming.ts | 18 ++++---- .../src/__tests__/unary.ts | 24 +++++------ .../src/__tests__/bidiStreaming.ts | 12 +++--- .../src/__tests__/clientStreaming.ts | 8 ++-- .../src/__tests__/customMetrics.ts | 8 ++-- .../src/__tests__/serverStreaming.ts | 12 +++--- .../src/__tests__/unary.ts | 16 +++---- .../nice-grpc-server-health/src/index.test.ts | 16 +++---- .../src/index.test.ts | 12 +++--- packages/nice-grpc-web/package.json | 2 + packages/nice-grpc-web/src/__tests__/unary.ts | 2 +- packages/nice-grpc/package.json | 2 - .../nice-grpc/src/__tests__/bidiStreaming.ts | 43 ++++++------------- packages/nice-grpc/src/__tests__/channel.ts | 13 ++---- .../clientMiddleware/bidiStreaming.ts | 13 ++---- .../src/__tests__/clientMiddleware/chain.ts | 13 ++---- .../clientMiddleware/clientStreaming.ts | 13 ++---- .../clientMiddleware/serverStreaming.ts | 13 ++---- .../src/__tests__/clientMiddleware/unary.ts | 13 ++---- .../src/__tests__/clientStreaming.ts | 43 ++++++------------- .../src/__tests__/defaultCallOptions.ts | 7 +-- .../nice-grpc/src/__tests__/serverClass.ts | 7 +-- .../serverMiddleware/bidiStreaming.ts | 13 ++---- .../src/__tests__/serverMiddleware/chain.ts | 7 +-- .../serverMiddleware/clientStreaming.ts | 13 ++---- .../__tests__/serverMiddleware/perService.ts | 7 +-- .../serverMiddleware/serverStreaming.ts | 13 ++---- .../src/__tests__/serverMiddleware/unary.ts | 13 ++---- .../src/__tests__/serverStreaming.ts | 43 ++++++------------- packages/nice-grpc/src/__tests__/ts-proto.ts | 13 ++---- packages/nice-grpc/src/__tests__/unary.ts | 31 +++++-------- 37 files changed, 201 insertions(+), 325 deletions(-) diff --git a/packages/nice-grpc-client-middleware-deadline/src/index.test.ts b/packages/nice-grpc-client-middleware-deadline/src/index.test.ts index 657adedb..14effdca 100644 --- a/packages/nice-grpc-client-middleware-deadline/src/index.test.ts +++ b/packages/nice-grpc-client-middleware-deadline/src/index.test.ts @@ -1,4 +1,3 @@ -import defer = require('defer-promise'); import {forever} from 'abort-controller-x'; import { createChannel, @@ -27,9 +26,9 @@ test('successful call', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(deadlineMiddleware) .create(TestService, channel); @@ -57,9 +56,9 @@ test('absolute deadline', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(deadlineMiddleware) .create(TestService, channel); @@ -89,9 +88,9 @@ test('relative deadline', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(deadlineMiddleware) .create(TestService, channel); diff --git a/packages/nice-grpc-client-middleware-retry/src/index.test.ts b/packages/nice-grpc-client-middleware-retry/src/index.test.ts index 35e64694..973b4537 100644 --- a/packages/nice-grpc-client-middleware-retry/src/index.test.ts +++ b/packages/nice-grpc-client-middleware-retry/src/index.test.ts @@ -31,9 +31,9 @@ test('basic', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(retryMiddleware) .create(TestDefinition, channel); @@ -71,9 +71,9 @@ test('retries enabled', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(retryMiddleware) .create(TestDefinition, channel); @@ -120,9 +120,9 @@ test('idempotent', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(retryMiddleware) .create(TestDefinition, channel); diff --git a/packages/nice-grpc-error-details/src/index.test.ts b/packages/nice-grpc-error-details/src/index.test.ts index 22ed0d00..c001f724 100644 --- a/packages/nice-grpc-error-details/src/index.test.ts +++ b/packages/nice-grpc-error-details/src/index.test.ts @@ -34,9 +34,9 @@ const beforeEachServerAndClientTest = async ( }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const rawClient = createClient(TestDefinition, channel); diff --git a/packages/nice-grpc-opentelemetry/src/__tests__/bidiStreaming.ts b/packages/nice-grpc-opentelemetry/src/__tests__/bidiStreaming.ts index 2691d21b..9533f9fa 100644 --- a/packages/nice-grpc-opentelemetry/src/__tests__/bidiStreaming.ts +++ b/packages/nice-grpc-opentelemetry/src/__tests__/bidiStreaming.ts @@ -46,9 +46,9 @@ test('basic', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -120,7 +120,7 @@ test('basic', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 0, "rpc.grpc.status_text": "OK", "rpc.method": "TestBidiStream", @@ -185,9 +185,9 @@ test('error', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -249,7 +249,7 @@ test('error', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 5, "rpc.grpc.status_text": "NOT_FOUND", "rpc.method": "TestBidiStream", @@ -295,9 +295,9 @@ test('aborted iteration on client', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -365,7 +365,7 @@ test('aborted iteration on client', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 1, "rpc.grpc.status_text": "CANCELLED", "rpc.method": "TestBidiStream", diff --git a/packages/nice-grpc-opentelemetry/src/__tests__/clientStreaming.ts b/packages/nice-grpc-opentelemetry/src/__tests__/clientStreaming.ts index 0339710c..e4f199c6 100644 --- a/packages/nice-grpc-opentelemetry/src/__tests__/clientStreaming.ts +++ b/packages/nice-grpc-opentelemetry/src/__tests__/clientStreaming.ts @@ -46,9 +46,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -105,7 +105,7 @@ test('basic', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 0, "rpc.grpc.status_text": "OK", "rpc.method": "TestClientStream", @@ -157,9 +157,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -216,7 +216,7 @@ test('error', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 5, "rpc.grpc.status_text": "NOT_FOUND", "rpc.method": "TestClientStream", diff --git a/packages/nice-grpc-opentelemetry/src/__tests__/context.ts b/packages/nice-grpc-opentelemetry/src/__tests__/context.ts index f524f42b..4d7d0ec2 100644 --- a/packages/nice-grpc-opentelemetry/src/__tests__/context.ts +++ b/packages/nice-grpc-opentelemetry/src/__tests__/context.ts @@ -58,9 +58,9 @@ test('context propagation', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(async function* testClientMiddleware(call, options) { traceIdInClientMiddlewareStart = getCurrentTraceId(); diff --git a/packages/nice-grpc-opentelemetry/src/__tests__/serverStreaming.ts b/packages/nice-grpc-opentelemetry/src/__tests__/serverStreaming.ts index 2e008eef..462595e6 100644 --- a/packages/nice-grpc-opentelemetry/src/__tests__/serverStreaming.ts +++ b/packages/nice-grpc-opentelemetry/src/__tests__/serverStreaming.ts @@ -45,9 +45,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -100,7 +100,7 @@ test('basic', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 0, "rpc.grpc.status_text": "OK", "rpc.method": "TestServerStream", @@ -150,9 +150,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -202,7 +202,7 @@ test('error', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 5, "rpc.grpc.status_text": "NOT_FOUND", "rpc.method": "TestServerStream", @@ -245,9 +245,9 @@ test('aborted iteration on client', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -296,7 +296,7 @@ test('aborted iteration on client', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 1, "rpc.grpc.status_text": "CANCELLED", "rpc.method": "TestServerStream", diff --git a/packages/nice-grpc-opentelemetry/src/__tests__/unary.ts b/packages/nice-grpc-opentelemetry/src/__tests__/unary.ts index 297b39ea..b53b2a88 100644 --- a/packages/nice-grpc-opentelemetry/src/__tests__/unary.ts +++ b/packages/nice-grpc-opentelemetry/src/__tests__/unary.ts @@ -45,9 +45,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -84,7 +84,7 @@ test('basic', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 0, "rpc.grpc.status_text": "OK", "rpc.method": "TestUnary", @@ -118,9 +118,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -157,7 +157,7 @@ test('error', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 5, "rpc.grpc.status_text": "NOT_FOUND", "rpc.method": "TestUnary", @@ -191,9 +191,9 @@ test('unknown error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -235,7 +235,7 @@ test('unknown error', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 2, "rpc.grpc.status_text": "UNKNOWN", "rpc.method": "TestUnary", @@ -281,9 +281,9 @@ test('cancel', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(openTelemetryClientMiddleware()) .create(TestDefinition, channel); @@ -328,7 +328,7 @@ test('cancel', async () => { expect(dumpSpan(serverSpan)).toMatchInlineSnapshot(` { "attributes": { - "net.peer.ip": "::1", + "net.peer.ip": "127.0.0.1", "rpc.grpc.status_code": 1, "rpc.grpc.status_text": "CANCELLED", "rpc.method": "TestUnary", diff --git a/packages/nice-grpc-prometheus/src/__tests__/bidiStreaming.ts b/packages/nice-grpc-prometheus/src/__tests__/bidiStreaming.ts index 8b311a3f..dc62525e 100644 --- a/packages/nice-grpc-prometheus/src/__tests__/bidiStreaming.ts +++ b/packages/nice-grpc-prometheus/src/__tests__/bidiStreaming.ts @@ -33,9 +33,9 @@ test('basic', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -138,9 +138,9 @@ test('error', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -247,9 +247,9 @@ test('aborted iteration on client', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); diff --git a/packages/nice-grpc-prometheus/src/__tests__/clientStreaming.ts b/packages/nice-grpc-prometheus/src/__tests__/clientStreaming.ts index 1826b2bb..4dc8d2d0 100644 --- a/packages/nice-grpc-prometheus/src/__tests__/clientStreaming.ts +++ b/packages/nice-grpc-prometheus/src/__tests__/clientStreaming.ts @@ -33,9 +33,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -136,9 +136,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); diff --git a/packages/nice-grpc-prometheus/src/__tests__/customMetrics.ts b/packages/nice-grpc-prometheus/src/__tests__/customMetrics.ts index c1f079cb..12740bb6 100644 --- a/packages/nice-grpc-prometheus/src/__tests__/customMetrics.ts +++ b/packages/nice-grpc-prometheus/src/__tests__/customMetrics.ts @@ -114,9 +114,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use( prometheusClientMiddleware({ @@ -205,9 +205,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use( prometheusClientMiddleware({ diff --git a/packages/nice-grpc-prometheus/src/__tests__/serverStreaming.ts b/packages/nice-grpc-prometheus/src/__tests__/serverStreaming.ts index 0be07602..986b7f28 100644 --- a/packages/nice-grpc-prometheus/src/__tests__/serverStreaming.ts +++ b/packages/nice-grpc-prometheus/src/__tests__/serverStreaming.ts @@ -32,9 +32,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -129,9 +129,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -230,9 +230,9 @@ test('aborted iteration on client', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); diff --git a/packages/nice-grpc-prometheus/src/__tests__/unary.ts b/packages/nice-grpc-prometheus/src/__tests__/unary.ts index b4ea18a5..e98cde2f 100644 --- a/packages/nice-grpc-prometheus/src/__tests__/unary.ts +++ b/packages/nice-grpc-prometheus/src/__tests__/unary.ts @@ -32,9 +32,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -125,9 +125,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -218,9 +218,9 @@ test('unknown error', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); @@ -315,9 +315,9 @@ test('cancel', async () => { testBidiStream: throwUnimplemented, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(prometheusClientMiddleware()) .create(TestDefinition, channel); diff --git a/packages/nice-grpc-server-health/src/index.test.ts b/packages/nice-grpc-server-health/src/index.test.ts index d646ba32..f5beda95 100644 --- a/packages/nice-grpc-server-health/src/index.test.ts +++ b/packages/nice-grpc-server-health/src/index.test.ts @@ -10,9 +10,9 @@ test('basic', async () => { server.add(HealthDefinition, HealthServiceImpl()); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(HealthDefinition, channel); await expect(client.check({service: ''})).resolves.toMatchInlineSnapshot(` @@ -36,9 +36,9 @@ test('per-service', async () => { server.add(HealthDefinition, HealthServiceImpl(healthState)); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(HealthDefinition, channel); await expect(client.check({service: ''})).resolves.toMatchInlineSnapshot(` @@ -92,9 +92,9 @@ test('watch', async () => { server.add(HealthDefinition, HealthServiceImpl(healthState)); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(HealthDefinition, channel); const it1 = client.watch({service: ''})[Symbol.asyncIterator](); @@ -171,7 +171,7 @@ test.skipWindows('grpc-health-probe', async () => { server.add(HealthDefinition, HealthServiceImpl(healthState)); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); const execProbe = (...args: string[]) => new Promise<{stderr: string; code: number | null}>(resolve => { @@ -182,7 +182,7 @@ test.skipWindows('grpc-health-probe', async () => { 'grpc-health-probe', 'grpc-health-probe', )}`, - ['-addr', `localhost:${port}`, ...args], + ['-addr', `127.0.0.1:${port}`, ...args], ); let stderr = ''; diff --git a/packages/nice-grpc-server-middleware-terminator/src/index.test.ts b/packages/nice-grpc-server-middleware-terminator/src/index.test.ts index 79408fa1..9bfc0254 100644 --- a/packages/nice-grpc-server-middleware-terminator/src/index.test.ts +++ b/packages/nice-grpc-server-middleware-terminator/src/index.test.ts @@ -30,9 +30,9 @@ test('basic', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestDefinition, channel); const promise = client.testUnary({}); @@ -65,9 +65,9 @@ test('terminate before call start', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestDefinition, channel); terminatorMiddleware.terminate(); @@ -106,9 +106,9 @@ test('cancel', async () => { }, }); - const port = await server.listen('localhost:0'); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`localhost:${port}`); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestDefinition, channel); const abortController = new AbortController(); diff --git a/packages/nice-grpc-web/package.json b/packages/nice-grpc-web/package.json index 17109113..4cb01f7d 100644 --- a/packages/nice-grpc-web/package.json +++ b/packages/nice-grpc-web/package.json @@ -43,6 +43,7 @@ "@babel/preset-env": "^7.20.2", "@improbable-eng/grpc-web": "^0.15.0", "@tsconfig/recommended": "^1.0.1", + "@types/get-port": "^4.2.0", "@types/google-protobuf": "^3.15.2", "@types/jasmine": "^4.3.1", "@types/karma": "^6.3.3", @@ -53,6 +54,7 @@ "chromedriver": "^113.0.0", "cpr": "^3.0.1", "detect-browser": "^5.3.0", + "get-port": "^5.1.1", "google-protobuf": "^3.17.3", "grpc-tools": "^1.11.2", "jasmine": "^4.5.0", diff --git a/packages/nice-grpc-web/src/__tests__/unary.ts b/packages/nice-grpc-web/src/__tests__/unary.ts index e677cec1..de8e839f 100644 --- a/packages/nice-grpc-web/src/__tests__/unary.ts +++ b/packages/nice-grpc-web/src/__tests__/unary.ts @@ -469,7 +469,7 @@ const environment = detect(); new ClientError( '/nice_grpc.test.Test2/TestUnary', Status.UNIMPLEMENTED, - '[object Object]', // this is a bug in grpc-js + 'The server does not implement the method /nice_grpc.test.Test2/TestUnary', ), ); }); diff --git a/packages/nice-grpc/package.json b/packages/nice-grpc/package.json index 6d882e8b..e855fd32 100644 --- a/packages/nice-grpc/package.json +++ b/packages/nice-grpc/package.json @@ -34,11 +34,9 @@ "devDependencies": { "@tsconfig/node14": "^14.1.0", "@types/defer-promise": "^1.0.0", - "@types/get-port": "^4.2.0", "@types/google-protobuf": "^3.7.4", "@types/node": "^14.18.23", "defer-promise": "^2.0.1", - "get-port": "^5.1.1", "google-protobuf": "^3.14.0", "grpc-tools": "^1.10.0", "grpc_tools_node_protoc_ts": "^5.0.1", diff --git a/packages/nice-grpc/src/__tests__/bidiStreaming.ts b/packages/nice-grpc/src/__tests__/bidiStreaming.ts index 9158face..9a491d10 100644 --- a/packages/nice-grpc/src/__tests__/bidiStreaming.ts +++ b/packages/nice-grpc/src/__tests__/bidiStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import defer = require('defer-promise'); import {forever, isAbortError} from 'abort-controller-x'; import { @@ -31,11 +30,9 @@ test('basic', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { @@ -91,11 +88,9 @@ test('metadata', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const headerDeferred = defer(); @@ -205,11 +200,9 @@ test('implicit header sending', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const metadata = Metadata(); @@ -260,11 +253,9 @@ test('error', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const responses: any[] = []; @@ -350,11 +341,9 @@ test('cancel', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const abortController = new AbortController(); @@ -437,11 +426,9 @@ test('early response', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const requestIterableFinish = defer(); @@ -506,11 +493,9 @@ test('request iterable error', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { diff --git a/packages/nice-grpc/src/__tests__/channel.ts b/packages/nice-grpc/src/__tests__/channel.ts index d6d1df16..d1110fae 100644 --- a/packages/nice-grpc/src/__tests__/channel.ts +++ b/packages/nice-grpc/src/__tests__/channel.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {randomBytes} from 'crypto'; import { createChannel, @@ -9,13 +8,11 @@ import { } from '..'; test('implicit protocol', async () => { - const address = `localhost:${await getPort()}`; - const server = createServer(); - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); await waitForChannelReady(channel, new Date(Date.now() + 1000)); channel.close(); @@ -23,13 +20,11 @@ test('implicit protocol', async () => { }); test('http', async () => { - const address = `localhost:${await getPort()}`; - const server = createServer(); - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(`http://${address}`); + const channel = createChannel(`http://127.0.0.1:${port}`); await waitForChannelReady(channel, new Date(Date.now() + 1000)); channel.close(); diff --git a/packages/nice-grpc/src/__tests__/clientMiddleware/bidiStreaming.ts b/packages/nice-grpc/src/__tests__/clientMiddleware/bidiStreaming.ts index 290319fc..34135072 100644 --- a/packages/nice-grpc/src/__tests__/clientMiddleware/bidiStreaming.ts +++ b/packages/nice-grpc/src/__tests__/clientMiddleware/bidiStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClientFactory, @@ -31,11 +30,9 @@ test('basic', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); @@ -128,11 +125,9 @@ test('error', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); diff --git a/packages/nice-grpc/src/__tests__/clientMiddleware/chain.ts b/packages/nice-grpc/src/__tests__/clientMiddleware/chain.ts index c24be0a0..0d70b236 100644 --- a/packages/nice-grpc/src/__tests__/clientMiddleware/chain.ts +++ b/packages/nice-grpc/src/__tests__/clientMiddleware/chain.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {createChannel, createClientFactory, createServer} from '../..'; import {TestService} from '../../../fixtures/grpc-js/test_grpc_pb'; import {TestRequest, TestResponse} from '../../../fixtures/grpc-js/test_pb'; @@ -19,11 +18,9 @@ test('chain', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption1', actions, 'middleware-1-')) .use(createTestClientMiddleware('testOption2', actions, 'middleware-2-')) @@ -104,11 +101,9 @@ test('set option from middleware', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use<{testOption1: string}>(async function* middleware1(call, options) { const {testOption1, ...restOptions} = options; diff --git a/packages/nice-grpc/src/__tests__/clientMiddleware/clientStreaming.ts b/packages/nice-grpc/src/__tests__/clientMiddleware/clientStreaming.ts index 368bb2f8..5b7e18c1 100644 --- a/packages/nice-grpc/src/__tests__/clientMiddleware/clientStreaming.ts +++ b/packages/nice-grpc/src/__tests__/clientMiddleware/clientStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClientFactory, @@ -37,11 +36,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); @@ -121,11 +118,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); diff --git a/packages/nice-grpc/src/__tests__/clientMiddleware/serverStreaming.ts b/packages/nice-grpc/src/__tests__/clientMiddleware/serverStreaming.ts index 1ba5b3e5..6c2db1d8 100644 --- a/packages/nice-grpc/src/__tests__/clientMiddleware/serverStreaming.ts +++ b/packages/nice-grpc/src/__tests__/clientMiddleware/serverStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClientFactory, @@ -29,11 +28,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); @@ -117,11 +114,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); diff --git a/packages/nice-grpc/src/__tests__/clientMiddleware/unary.ts b/packages/nice-grpc/src/__tests__/clientMiddleware/unary.ts index cd3df44d..8a679c59 100644 --- a/packages/nice-grpc/src/__tests__/clientMiddleware/unary.ts +++ b/packages/nice-grpc/src/__tests__/clientMiddleware/unary.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClientFactory, @@ -28,11 +27,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); @@ -97,11 +94,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClientFactory() .use(createTestClientMiddleware('testOption', actions)) .create(TestService, channel); diff --git a/packages/nice-grpc/src/__tests__/clientStreaming.ts b/packages/nice-grpc/src/__tests__/clientStreaming.ts index 6a2c5578..7975b62e 100644 --- a/packages/nice-grpc/src/__tests__/clientStreaming.ts +++ b/packages/nice-grpc/src/__tests__/clientStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import defer = require('defer-promise'); import {forever, isAbortError} from 'abort-controller-x'; import { @@ -37,11 +36,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { @@ -90,11 +87,9 @@ test('metadata', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const headerDeferred = defer(); @@ -198,11 +193,9 @@ test('implicit header sending', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const metadata = Metadata(); @@ -253,11 +246,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); let trailer: Metadata | undefined; @@ -330,11 +321,9 @@ test('cancel', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const abortController = new AbortController(); @@ -398,11 +387,9 @@ test('early response', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const requestIterableFinish = defer(); @@ -457,11 +444,9 @@ test('request iterable error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { diff --git a/packages/nice-grpc/src/__tests__/defaultCallOptions.ts b/packages/nice-grpc/src/__tests__/defaultCallOptions.ts index bbcfbbd5..d0de3a58 100644 --- a/packages/nice-grpc/src/__tests__/defaultCallOptions.ts +++ b/packages/nice-grpc/src/__tests__/defaultCallOptions.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {Channel} from '@grpc/grpc-js'; import {createChannel, createClient, createServer, Metadata, Server} from '..'; import {TestService} from '../../fixtures/grpc-js/test_grpc_pb'; @@ -21,11 +20,9 @@ beforeEach(async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - channel = createChannel(address); + channel = createChannel(`127.0.0.1:${port}`); }); afterEach(async () => { diff --git a/packages/nice-grpc/src/__tests__/serverClass.ts b/packages/nice-grpc/src/__tests__/serverClass.ts index 4436c034..6363c1ed 100644 --- a/packages/nice-grpc/src/__tests__/serverClass.ts +++ b/packages/nice-grpc/src/__tests__/serverClass.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClient, @@ -34,11 +33,9 @@ test('server class', async () => { server.add(TestService, new TestServer()); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); await expect(client.testUnary(new TestRequest().setId('test'))).resolves diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/bidiStreaming.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/bidiStreaming.ts index 003cd713..a3dbd2f7 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/bidiStreaming.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/bidiStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClient, @@ -33,11 +32,9 @@ test('basic', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { @@ -120,11 +117,9 @@ test('error', async () => { }, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/chain.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/chain.ts index 76ec775b..8aca8332 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/chain.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/chain.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {createChannel, createClient, createServer} from '../..'; import {TestService} from '../../../fixtures/grpc-js/test_grpc_pb'; import {TestRequest, TestResponse} from '../../../fixtures/grpc-js/test_pb'; @@ -38,11 +37,9 @@ test('chain', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); await expect(client.testUnary(new TestRequest().setId('test'))).resolves diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/clientStreaming.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/clientStreaming.ts index 80bf2527..7e53f3a3 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/clientStreaming.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/clientStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClient, @@ -39,11 +38,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { @@ -112,11 +109,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); async function* createRequest() { diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/perService.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/perService.ts index a59bd1e4..2b04adf4 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/perService.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/perService.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {createChannel, createClient, createServer} from '../..'; import { Test2Service, @@ -52,11 +51,9 @@ test('per service', async () => { }, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const testClient = createClient(TestService, channel); const test2Client = createClient(Test2Service, channel); diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/serverStreaming.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/serverStreaming.ts index eb40df58..2647734b 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/serverStreaming.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/serverStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClient, @@ -31,11 +30,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const responses: any[] = []; @@ -108,11 +105,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const responses: any[] = []; diff --git a/packages/nice-grpc/src/__tests__/serverMiddleware/unary.ts b/packages/nice-grpc/src/__tests__/serverMiddleware/unary.ts index e4b3ed47..bdedf140 100644 --- a/packages/nice-grpc/src/__tests__/serverMiddleware/unary.ts +++ b/packages/nice-grpc/src/__tests__/serverMiddleware/unary.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import { createChannel, createClient, @@ -30,11 +29,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); await expect(client.testUnary(new TestRequest().setId('test'))).resolves @@ -88,11 +85,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); await expect( diff --git a/packages/nice-grpc/src/__tests__/serverStreaming.ts b/packages/nice-grpc/src/__tests__/serverStreaming.ts index a98580c3..771b8c5a 100644 --- a/packages/nice-grpc/src/__tests__/serverStreaming.ts +++ b/packages/nice-grpc/src/__tests__/serverStreaming.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import defer = require('defer-promise'); import {forever, isAbortError} from 'abort-controller-x'; import { @@ -30,11 +29,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const responses: any[] = []; @@ -87,11 +84,9 @@ test('metadata', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const headerDeferred = defer(); @@ -193,11 +188,9 @@ test('implicit header sending', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const metadata = Metadata(); @@ -243,11 +236,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const responses: any[] = []; @@ -319,11 +310,9 @@ test('cancel', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const abortController = new AbortController(); @@ -381,11 +370,9 @@ test('high rate', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); let i = 0; @@ -425,11 +412,9 @@ test('aborted iteration on client', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const iterable = client.testServerStream(new TestRequest().setId('test')); diff --git a/packages/nice-grpc/src/__tests__/ts-proto.ts b/packages/nice-grpc/src/__tests__/ts-proto.ts index 61482262..a5629c03 100644 --- a/packages/nice-grpc/src/__tests__/ts-proto.ts +++ b/packages/nice-grpc/src/__tests__/ts-proto.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import {ClientMiddleware, ServerMiddleware} from 'nice-grpc-common'; import {createChannel, createClient, createServer} from '..'; import { @@ -31,11 +30,9 @@ test('basic', async () => { server.add(TestDefinition, impl); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client: TestClient = createClient(TestDefinition, channel); await expect(client.testUnary({id: 'test'})).resolves.toMatchInlineSnapshot(` @@ -76,9 +73,7 @@ test('middleware', async () => { server.with(serverMiddleware).add(Test2Definition, impl); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); const clientMiddlewareCalls: any[] = []; @@ -92,7 +87,7 @@ test('middleware', async () => { return yield* call.next(call.request, rest); }; - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client: Test2Client<{bar: 'baz'}> = createClientFactory() .use(clientMiddleware) .create(Test2Definition, channel); diff --git a/packages/nice-grpc/src/__tests__/unary.ts b/packages/nice-grpc/src/__tests__/unary.ts index 47f851d0..07bea45a 100644 --- a/packages/nice-grpc/src/__tests__/unary.ts +++ b/packages/nice-grpc/src/__tests__/unary.ts @@ -1,4 +1,3 @@ -import getPort = require('get-port'); import defer = require('defer-promise'); import {forever, isAbortError} from 'abort-controller-x'; import { @@ -29,11 +28,9 @@ test('basic', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); await expect(client.testUnary(new TestRequest().setId('test'))).resolves @@ -76,11 +73,9 @@ test('metadata', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const headerDeferred = defer(); @@ -172,11 +167,9 @@ test('implicit header sending', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const metadata = Metadata(); @@ -218,11 +211,9 @@ test('error', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; + const port = await server.listen('127.0.0.1:0'); - await server.listen(address); - - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); let trailer: Metadata | undefined; @@ -274,11 +265,9 @@ test('cancel', async () => { testBidiStream: throwUnimplemented, }); - const address = `localhost:${await getPort()}`; - - await server.listen(address); + const port = await server.listen('127.0.0.1:0'); - const channel = createChannel(address); + const channel = createChannel(`127.0.0.1:${port}`); const client = createClient(TestService, channel); const abortController = new AbortController();