Skip to content

Commit

Permalink
test: fix API test flakiness (#30657)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Nov 1, 2023
1 parent da416dc commit d39aa04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 9 additions & 10 deletions apps/meteor/packages/rocketchat-mongo-config/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ if (Object.keys(mongoConnectionOptions).length > 0) {

process.env.HTTP_FORWARDED_COUNT = process.env.HTTP_FORWARDED_COUNT || '1';

// Send emails to a "fake" stream instead of print them in console in case MAIL_URL or SMTP is not configured
if (process.env.NODE_ENV !== 'development') {
const { sendAsync } = Email;
// Just print to logs if in TEST_MODE due to a bug in Meteor 2.5: TypeError: Cannot read property '_syncSendMail' of null
if (process.env.TEST_MODE === 'true') {
Email.sendAsync = function _sendAsync(options) {
console.log('Email.sendAsync', options);
};
} else if (process.env.NODE_ENV !== 'development') {
// Send emails to a "fake" stream instead of print them in console in case MAIL_URL or SMTP is not configured
const stream = new PassThrough();
stream.on('data', () => {});
stream.on('end', () => {});
Email.sendAsync = function _sendAsync(options) {
return sendAsync.call(this, { stream, ...options });
};
}

// Just print to logs if in TEST_MODE due to a bug in Meteor 2.5: TypeError: Cannot read property '_syncSendMail' of null
if (process.env.TEST_MODE === 'true') {
const { sendAsync } = Email;
Email.sendAsync = function _sendAsync(options) {
console.log('Email.sendAsync', options);
return sendAsync.call(this, { stream, ...options });
};
}
6 changes: 2 additions & 4 deletions apps/meteor/server/lib/dataExport/uploadZipFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createReadStream } from 'fs';
import { open, stat } from 'fs/promises';
import { stat } from 'fs/promises';

import type { IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';
Expand Down Expand Up @@ -28,9 +28,7 @@ export const uploadZipFile = async (filePath: string, userId: IUser['_id'], expo
name: newFileName,
};

const { fd } = await open(filePath);

const stream = createReadStream('', { fd }); // @todo once upgrades to Node.js v16.x, use createReadStream from fs.promises.open
const stream = createReadStream(filePath);

const userDataStore = FileUpload.getStore('UserDataFiles');

Expand Down

0 comments on commit d39aa04

Please sign in to comment.