From 91305a96537813bf662206bb89000cbf39b972d5 Mon Sep 17 00:00:00 2001 From: f-w Date: Wed, 13 Dec 2023 15:51:56 -0800 Subject: [PATCH] replaced fetch with axios due to timeout --- .github/values.ocp4.dev.yaml.gpg | Bin 1460 -> 1472 bytes .../buildTestPublishContainerDeploy.yml | 1 + package.json | 1 + .../notifications/notifications.controller.ts | 20 +++++----- src/config.ts | 17 -------- test/notification.e2e-spec.ts | 37 ++++++------------ yarn.lock | 16 +++++++- 7 files changed, 39 insertions(+), 53 deletions(-) diff --git a/.github/values.ocp4.dev.yaml.gpg b/.github/values.ocp4.dev.yaml.gpg index a429c2cc2467fddc25103f250047433d5c68b15d..0bbdf8a98fafdad2904fb977e8acdfb2388bb8ba 100644 GIT binary patch literal 1472 zcmV;x1wZ6cTq1pZjzKR&Z zyxGdlc8$~T@-g`P3#R25PF852;p0CZEz-7(uFC|B&L)OXmZ+m&Xc?lX+eK9;E^_Z`-OM2-=J~@g4#vy!MYWSB0*I2h z*nur|Blywni!bxIorP@amyDEjZdrzXZo7%~_X z2xez0BKv_9kz|YUhn=W5#YMCvUuQ6I>eTtRzS&Mx#_wn<(J>)b$9t6Qx=sqg5)24y z9%W8Mmlw7o-BfL?O_V}5y^r6|P>p1v4YnSydv=~k%|7s4C180XZ~sY1l`)L_UthK^ z;`rJ-!M@5~N~wM;N+VXcaZ_V%HvBc`!Z5+&-lEp-T!duopVrwhgSZaN`cgiV--MXR z#^>e&KuMQ*^k|^_X)?@KS6kHT@#gqG%)o#X4%iM!#vz(rtqLvP|F8T;(@dRUW~O;= z(z0p@-~r_(7YW5r0i%ZTWFsR}p-;CIPY&-{^j;yD&bHIiP~%h?2q8V?7m*vc7&T(= zycwt*qe)Ty0O5vjF!T!ia1=>To>tN$2HE~Z@x8NRB=u2usB!8_Wxsn~0 zNjg}K7Q}}NvS>@jn1qu~2>tg1@ju22{y*n9eWpRc$*(dA=s08Zc{{cm{Hxx9)1wFi zn^$qRt_srP@ARYpORYdRPeYV zN^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/.github/workflows/buildTestPublishContainerDeploy.yml b/.github/workflows/buildTestPublishContainerDeploy.yml index 9ec36dd8a..af63c9dff 100644 --- a/.github/workflows/buildTestPublishContainerDeploy.yml +++ b/.github/workflows/buildTestPublishContainerDeploy.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - pullAll release: types: - published diff --git a/package.json b/package.json index 6bb60c528..f57e6ef1d 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.1.8", "async": "^3.2.4", + "axios": "^1.6.2", "bcryptjs": "^2.4.3", "bottleneck": "^2.19.5", "class-transformer": "^0.5.1", diff --git a/src/api/notifications/notifications.controller.ts b/src/api/notifications/notifications.controller.ts index 706bf87b5..b69ddf665 100644 --- a/src/api/notifications/notifications.controller.ts +++ b/src/api/notifications/notifications.controller.ts @@ -21,6 +21,7 @@ import { HttpException, HttpStatus, Inject, + Logger, Param, ParseIntPipe, Patch, @@ -40,6 +41,7 @@ import { ApiTags, } from '@nestjs/swagger'; import { queue } from 'async'; +import axios from 'axios'; import { Request } from 'express'; import jmespath from 'jmespath'; import { pullAll } from 'lodash'; @@ -300,6 +302,10 @@ export class NotificationsController extends BaseController { this.appConfig.notification?.guaranteedBroadcastPushDispatchProcessing ) { this.req.on('close', () => { + Logger.debug( + 'request close. chunkRequestAborted', + NotificationsController.name, + ); this.chunkRequestAborted = true; }); } @@ -744,15 +750,8 @@ export class NotificationsController extends BaseController { data.id + '/broadcastToChunkSubscribers?start=' + task.startIdx; - const response = await fetch(uri); - if (response.status < 300) { - try { - return await response.json(); - } catch (ex) { - return response.body; - } - } - throw new HttpException(undefined, response.status); + const response = await axios.get(uri); + return response.data; }, broadcastSubRequestBatchSize); // re-submit task on error if // guaranteedBroadcastPushDispatchProcessing. @@ -760,6 +759,9 @@ export class NotificationsController extends BaseController { let failedChunks: any[] = []; q.error((_err: any, task: any) => { if (this.guaranteedBroadcastPushDispatchProcessing) { + Logger.debug('re-push task', NotificationsController.name); + Logger.debug(task, NotificationsController.name); + Logger.debug(_err, NotificationsController.name); q.push(task); } else { data.state = 'error'; diff --git a/src/config.ts b/src/config.ts index b57cfc4b4..bf2f85e59 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,23 +35,6 @@ const config: Record = { host: '0.0.0.0', // port listen on port: 3000, - remoting: { - rest: { - normalizeHttpPath: false, - xml: false, - handleErrors: false, - }, - json: { - strict: false, - limit: '100kb', - }, - urlencoded: { - extended: true, - limit: '100kb', - }, - cors: false, - }, - legacyExplorer: false, adminIps: ['127.0.0.1'], siteMinderReverseProxyIps: ['127.0.0.1'], email: { diff --git a/test/notification.e2e-spec.ts b/test/notification.e2e-spec.ts index ae28b4fd5..d9d63b256 100644 --- a/test/notification.e2e-spec.ts +++ b/test/notification.e2e-spec.ts @@ -14,6 +14,7 @@ import { HttpException, HttpStatus } from '@nestjs/common'; import { NestExpressApplication } from '@nestjs/platform-express'; +import axios from 'axios'; import dns from 'dns'; import { merge } from 'lodash'; import nodemailer from 'nodemailer'; @@ -838,7 +839,7 @@ describe('POST /notifications', () => { broadcastSubRequestBatchSize: 10, }); appConfig.notification = newNotificationConfig; - const spiedFetch = jest.spyOn(global, 'fetch'); + const spiedAxios = jest.spyOn(axios, 'get'); const res = await client .post('/api/notifications') .send({ @@ -856,7 +857,7 @@ describe('POST /notifications', () => { expect( BaseController.prototype.sendEmail as unknown as jest.SpyInstance, ).toBeCalledTimes(2); - expect(spiedFetch).toBeCalledTimes(2); + expect(spiedAxios).toBeCalledTimes(2); const data = await notificationsService.findAll( { where: { @@ -882,28 +883,12 @@ describe('POST /notifications', () => { const spiedFetch = jest .spyOn(global, 'fetch') - .mockImplementation(async function (...args: any[]) { - if ( - args.length === 1 || - (args.length > 1 && args[1].method === undefined) - ) { - const getReq = client.get( - args[0].substring(args[0].indexOf('/api')), - ); - if (args[1]) { - for (const [p, v] of Object.entries(args[1].headers as object)) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - getReq.set(p, v); - } - } - const data: any = await getReq; - return new Response(JSON.stringify(data.body)); - } - if (args.length > 1 && args[1].method === 'POST') { - return new Response(); - } - throw new Error(); - }); + .mockResolvedValue(new Response()); + jest.spyOn(axios, 'get').mockImplementation(async (...args: any[]) => { + const getReq = client.get(args[0].substring(args[0].indexOf('/api'))); + const data: any = await getReq; + return new Response(JSON.stringify(data.body)); + }); ( BaseController.prototype.sendEmail as unknown as jest.SpyInstance @@ -1032,7 +1017,7 @@ describe('POST /notifications', () => { appConfig.notification = newNotificationConfig; const reqStub = jest - .spyOn(global, 'fetch') + .spyOn(axios, 'get') .mockRejectedValueOnce({ error: 'connection error' }); const res = await client .post('/api/notifications') @@ -1473,7 +1458,7 @@ describe('POST /notifications', () => { guaranteedBroadcastPushDispatchProcessing: false, }); appConfig.notification = newNotificationConfig; - jest.spyOn(global, 'fetch').mockRejectedValue({}); + jest.spyOn(axios, 'get').mockRejectedValue({}); const res = await client .post('/api/notifications') .send({ diff --git a/yarn.lock b/yarn.lock index e6fae6c45..5494a1c08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2355,6 +2355,15 @@ axios@^0.26.1: dependencies: follow-redirects "^1.14.8" +axios@^1.6.2: + version "1.6.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2" + integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babel-jest@^29.6.2: version "29.6.2" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.6.2.tgz#cada0a59e07f5acaeb11cbae7e3ba92aec9c1126" @@ -3610,7 +3619,7 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== -follow-redirects@^1.14.8: +follow-redirects@^1.14.8, follow-redirects@^1.15.0: version "1.15.3" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a" integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q== @@ -5704,6 +5713,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + pump@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"