Skip to content

Commit

Permalink
chore: Add sleep for flakey test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed Dec 29, 2022
1 parent 3964e57 commit 0045ec7
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions integration/grpc-js/grpc-js-test.ts
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
});
},
Expand All @@ -135,7 +135,7 @@ describe('grpc-js-test', () => {
server.addService(TestService, impl);

const port = await new Promise<number>((resolve, reject) => {
server.bindAsync('localhost:0', ServerCredentials.createInsecure(), (err, port) => {
server.bindAsync("localhost:0", ServerCredentials.createInsecure(), (err, port) => {
if (err) {
reject(err);
} else {
Expand All @@ -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);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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();
});

Expand Down

0 comments on commit 0045ec7

Please sign in to comment.