Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
viktree committed Feb 14, 2024
1 parent 53fea53 commit 183da66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/microservice/gcloud-pub-sub.server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ describe('GCloudPubSubServer', () => {
expect(server.client).toBe(null)
expect(server.subscriptions.length).toBe(0)
expect(server.options).toMatchInlineSnapshot(`
Object {
"authOptions": Object {
{
"authOptions": {
"projectId": "entitlement",
},
"subscriberOptions": Object {
"flowControl": Object {
"subscriberOptions": {
"flowControl": {
"allowExcessMessages": false,
"maxMessages": 5,
},
},
"subscriptionIds": Array [
"subscriptionIds": [
"create",
"update",
"delete",
Expand All @@ -71,11 +71,11 @@ describe('GCloudPubSubServer', () => {
expect(server2.client).toBe(null)
expect(server2.subscriptions.length).toBe(0)
expect(server2.options).toMatchInlineSnapshot(`
Object {
"authOptions": Object {
{
"authOptions": {
"projectId": "entitlement",
},
"subscriptionIds": Array [
"subscriptionIds": [
"create",
"update",
"delete",
Expand Down Expand Up @@ -137,21 +137,21 @@ describe('GCloudPubSubServer', () => {
message.ack.mockReset()
})

it('Acks the message and returns when no handler can be found', async () => {
it('Acks the message and returns when no handler can be found', () => {
server.listen(() => {})
const subscriptionName = 'my-subscription'
server.getHandlerByPattern = jest.fn(pattern => {
expect(pattern).toBe(subscriptionName)
return null
})
const handleMessage = await server.handleMessageFactory(subscriptionName)
const handleMessage = server.handleMessageFactory(subscriptionName)
// @ts-ignore
handleMessage(message)
expect(server.getHandlerByPattern).toHaveBeenCalled()
expect(message.ack).toHaveBeenCalled()
})

it('Calls the handler when a handler is found', async () => {
it('Calls the handler when a handler is found', () => {
const mockHandler = jest.fn()
const subscriptionName = 'my-subscription'
server.listen(() => {})
Expand All @@ -160,7 +160,7 @@ describe('GCloudPubSubServer', () => {
expect(pattern).toBe(subscriptionName)
return mockHandler
})
const handleMessage = await server.handleMessageFactory(subscriptionName)
const handleMessage = server.handleMessageFactory(subscriptionName)
// @ts-ignore
handleMessage(message)
expect(server.getHandlerByPattern).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -193,7 +193,6 @@ describe('GCloudPubSubServer', () => {
})

it('retries calling open on the subscription when error is in PUB_SUB_DEFAULT_RETRY_CODES', done => {
jest.setTimeout(TIMEOUT)
const subscription = {
close: jest.fn(),
open: jest.fn(() => {
Expand All @@ -212,7 +211,7 @@ describe('GCloudPubSubServer', () => {
expect(subscription.close).toHaveBeenCalled()
// @ts-ignore
expect(server.handleError).toHaveBeenCalledWith(error)
})
}, TIMEOUT)

it('does not attempt to handle subscription error retry when server is closing', () => {
jest.setTimeout(TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion src/microservice/gcloud-pub-sub.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GCloudPubSubServer extends Server implements CustomTransportStrateg
}

public handleErrorFactory(subscription: Subscription, subcriptionName: string) {
return error => {
return (error): void => {
this.handleError(error)
if (!this.isShuttingDown && PUB_SUB_DEFAULT_RETRY_CODES.includes(error.code)) {
this.logger.warn(`Closing subscription: ${subcriptionName}`)
Expand Down

0 comments on commit 183da66

Please sign in to comment.