From 0045ec74d2823c4977f6d062992ec73539a04662 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Thu, 29 Dec 2022 10:57:01 -0600 Subject: [PATCH] chore: Add sleep for flakey test. --- integration/grpc-js/grpc-js-test.ts | 51 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/integration/grpc-js/grpc-js-test.ts b/integration/grpc-js/grpc-js-test.ts index fd9a265a5..4a0aef646 100644 --- a/integration/grpc-js/grpc-js-test.ts +++ b/integration/grpc-js/grpc-js-test.ts @@ -8,15 +8,15 @@ import { ServerUnaryCall, sendUnaryData, ServiceError, -} from '@grpc/grpc-js'; -import { TestClient, TestServer, TestService } from './simple'; +} from "@grpc/grpc-js"; +import { TestClient, TestServer, TestService } from "./simple"; -describe('grpc-js-test', () => { - it('compiles', () => { +describe("grpc-js-test", () => { + it("compiles", () => { expect(TestService).not.toBeUndefined(); }); - it('can create a server and a client', async () => { + it("can create a server and a client", async () => { const server = new Server(); const impl: TestServer = { @@ -101,32 +101,32 @@ describe('grpc-js-test', () => { call.end(); }, clientStreaming(call, callback) { - call.on('data', (request) => { + call.on("data", (request) => { callback(null, { timestamp: request.timestamp, }); }); }, clientStreamingStringValue(call, callback) { - call.on('data', (request) => { + call.on("data", (request) => { callback(null, request); }); }, bidiStreaming(call) { - call.on('data', (request) => { + call.on("data", (request) => { call.write({ timestamp: request.timestamp, }); }); - call.on('end', () => { + call.on("end", () => { call.end(); }); }, bidiStreamingStringValue(call) { - call.on('data', (request) => { + call.on("data", (request) => { call.write(request); }); - call.on('end', () => { + call.on("end", () => { call.end(); }); }, @@ -135,7 +135,7 @@ describe('grpc-js-test', () => { server.addService(TestService, impl); const port = await new Promise((resolve, reject) => { - server.bindAsync('localhost:0', ServerCredentials.createInsecure(), (err, port) => { + server.bindAsync("localhost:0", ServerCredentials.createInsecure(), (err, port) => { if (err) { reject(err); } else { @@ -145,6 +145,9 @@ describe('grpc-js-test', () => { }); server.start(); + // Make sure the port is open + await new Promise((resolve) => setTimeout(resolve, 100)); + const client = new TestClient(`localhost:${port}`, ChannelCredentials.createInsecure()); expect.assertions(26); @@ -155,9 +158,9 @@ describe('grpc-js-test', () => { expect(res).toEqual({}); }); - client.unaryStringValue('foobar', (error: ServiceError | null, response: string | undefined) => { + client.unaryStringValue("foobar", (error: ServiceError | null, response: string | undefined) => { expect(error).toBeNull(); - expect(response).toEqual('foobar'); + expect(response).toEqual("foobar"); }); client.unaryBoolValue(true, (error: ServiceError | null, response: boolean | undefined) => { @@ -206,12 +209,12 @@ describe('grpc-js-test', () => { const timestamp = new Date(); const serverStreamingCall = client.serverStreaming({ timestamp }); - serverStreamingCall.on('data', (response) => { + serverStreamingCall.on("data", (response) => { expect(response.timestamp).toEqual(timestamp); }); - const serverStreamingStringValueCall = client.serverStreamingStringValue('foobar'); - serverStreamingStringValueCall.on('data', (response) => { - expect(response).toEqual('foobar'); + const serverStreamingStringValueCall = client.serverStreamingStringValue("foobar"); + serverStreamingStringValueCall.on("data", (response) => { + expect(response).toEqual("foobar"); }); const clientStreamingCall = client.clientStreaming((err, res) => { @@ -221,22 +224,22 @@ describe('grpc-js-test', () => { clientStreamingCall.end(); const clientStreamingStringValueCall = client.clientStreamingStringValue((err, res) => { - expect(res).toEqual('foobar'); + expect(res).toEqual("foobar"); }); - clientStreamingStringValueCall.write('foobar'); + clientStreamingStringValueCall.write("foobar"); clientStreamingStringValueCall.end(); const bidiStreamingCall = client.bidiStreaming(); bidiStreamingCall.write({ timestamp }); - bidiStreamingCall.on('data', (response) => { + bidiStreamingCall.on("data", (response) => { expect(response.timestamp).toEqual(timestamp); bidiStreamingCall.end(); }); const bidiStringValueStreamingCall = client.bidiStreamingStringValue(); - bidiStringValueStreamingCall.write('foobar'); - bidiStringValueStreamingCall.on('data', (response) => { - expect(response).toEqual('foobar'); + bidiStringValueStreamingCall.write("foobar"); + bidiStringValueStreamingCall.on("data", (response) => { + expect(response).toEqual("foobar"); bidiStringValueStreamingCall.end(); });