Skip to content

Commit

Permalink
add delay
Browse files Browse the repository at this point in the history
Signed-off-by: MregXN <[email protected]>
  • Loading branch information
MregXN committed Nov 28, 2023
1 parent c506be6 commit f5ff510
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/e2e/common/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ describe("common/server", () => {

await httpServer.start();
await grpcServer.start();
jest.setTimeout(8000); // Set the timeout to 8 seconds
});

beforeEach(() => {
jest.clearAllMocks();
jest.setTimeout(8000); // Set the timeout to 8 seconds
});

afterAll(async () => {
Expand All @@ -162,7 +162,7 @@ describe("common/server", () => {
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicWithStatusCb, protocol), "SUCCESS");
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeStatusHandler.mock.calls.length).toBe(1);
expect(mockSubscribeStatusHandler.mock.calls[0][1]).toEqual("SUCCESS");
expect(mockSubscribeDeadletterHandler.mock.calls.length).toBe(0);
Expand All @@ -179,7 +179,7 @@ describe("common/server", () => {
);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
// 3 as we retry twice
expect(mockSubscribeStatusHandler.mock.calls.length).toBe(3);
expect(mockSubscribeDeadletterHandler.mock.calls.length).toBe(0);
Expand All @@ -192,7 +192,7 @@ describe("common/server", () => {
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicWithStatusCb, protocol), "DROP");
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeStatusHandler.mock.calls.length).toBe(1);
expect(mockSubscribeStatusHandler.mock.calls[0][1]).toEqual("DROP");
},
Expand All @@ -202,7 +202,7 @@ describe("common/server", () => {
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicDefault, protocol), "Hello, world!");
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual("Hello, world!");
const headers = mockSubscribeHandler.mock.calls[0][1] as any;
Expand Down Expand Up @@ -324,7 +324,7 @@ describe("common/server", () => {
});
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
});
Expand All @@ -341,7 +341,7 @@ describe("common/server", () => {
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicDefault, protocol), ce);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1000));
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual("Hello, world!");
});
Expand All @@ -359,7 +359,7 @@ describe("common/server", () => {
const res = await server.client.pubsub.publish(pubSubName, getTopic(topicDefault, protocol), ce, options);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1000));
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
// The cloudevent should contain an inner cloudevent since the content type was application/json
const innerCe: any = mockSubscribeHandler.mock.calls[0][0];
Expand All @@ -376,7 +376,7 @@ describe("common/server", () => {
);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
const rawData: any = mockSubscribeHandler.mock.calls[0][0];
expect(rawData["data"]).toEqual("Hello, world!");
Expand All @@ -391,7 +391,7 @@ describe("common/server", () => {
});
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
const rawData: any = mockSubscribeHandler.mock.calls[0][0];
expect(rawData["data"]).toEqual({ message: "Hello, world!" });
Expand All @@ -409,7 +409,7 @@ describe("common/server", () => {
);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual("Hello, world!");
},
Expand All @@ -426,7 +426,7 @@ describe("common/server", () => {
);
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
},
Expand All @@ -440,7 +440,7 @@ describe("common/server", () => {
});
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
},
Expand Down Expand Up @@ -607,7 +607,7 @@ describe("common/server", () => {
});
expect(res.error).toBeUndefined();
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeErrorHandler).toHaveBeenCalledTimes(1);
expect(mockSubscribeErrorHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
expect(mockSubscribeHandler).toHaveBeenCalledTimes(0);
Expand All @@ -622,7 +622,7 @@ describe("common/server", () => {
message: "Hello, world!",
});
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
},
Expand All @@ -636,7 +636,7 @@ describe("common/server", () => {
message: "Hello, world!",
});
// Delay a bit for event to arrive
await new Promise((resolve, _reject) => setTimeout(resolve, 1500));
await new Promise((resolve, _reject) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(1);
expect(mockSubscribeHandler.mock.calls[0][0]).toEqual({ message: "Hello, world!" });
},
Expand All @@ -648,7 +648,7 @@ describe("common/server", () => {
const messages = ["message1", "message2", "message3"];
await server.client.pubsub.publishBulk(pubSubName, getTopic(topicWithBulk, protocol), messages);
// Delay a bit for events to arrive
await new Promise((resolve) => setTimeout(resolve, 1500));
await new Promise((resolve) => setTimeout(resolve, 2000));
expect(mockSubscribeHandler.mock.calls.length).toBe(3);
// Check that the messages are present
mockSubscribeHandler.mock.calls.forEach((call) => {
Expand Down

0 comments on commit f5ff510

Please sign in to comment.