Enable DownloadFile write stream error test (#3207)

Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/3207

Followup of D33191515 (e0afebeb32)

Reviewed By: mweststrate

Differential Revision: D33253520

fbshipit-source-id: 30bca740dd8674b9bbba4e157d27f2dcedbc5ed5
This commit is contained in:
Andrey Goncharov
2021-12-21 08:09:20 -08:00
committed by Facebook GitHub Bot
parent 0eaa647863
commit 5e3e777b5c

View File

@@ -19,10 +19,21 @@ describe('commands', () => {
typeof commandDownloadFileStartFactory typeof commandDownloadFileStartFactory
>; >;
let emit: jest.Mock<any>; let emit: jest.Mock<any>;
let tmpDirName: string;
let rmTmpDir: () => void;
beforeEach(() => { beforeEach(() => {
emit = jest.fn(); emit = jest.fn();
commandDownloadFileStart = commandDownloadFileStartFactory(emit); commandDownloadFileStart = commandDownloadFileStartFactory(emit);
const tmp = dirSync({
unsafeCleanup: true,
});
tmpDirName = tmp.name;
rmTmpDir = tmp.removeCallback;
});
afterEach(() => {
rmTmpDir();
}); });
test('downloads file and reports the progress', async () => { test('downloads file and reports the progress', async () => {
@@ -43,9 +54,6 @@ describe('commands', () => {
data: fakeDownloadStream, data: fakeDownloadStream,
})); }));
const {name: tmpDirName} = dirSync({
unsafeCleanup: true,
});
const dest = `${tmpDirName}/flipperTest`; const dest = `${tmpDirName}/flipperTest`;
expect(requestSpy).toBeCalledTimes(0); expect(requestSpy).toBeCalledTimes(0);
@@ -57,9 +65,6 @@ describe('commands', () => {
const downloadFileDescriptor = await commandDownloadFileStart( const downloadFileDescriptor = await commandDownloadFileStart(
fakeDownloadURL, fakeDownloadURL,
dest, dest,
{
overwrite: true,
},
); );
expect(requestSpy).toBeCalledTimes(1); expect(requestSpy).toBeCalledTimes(1);
@@ -126,18 +131,13 @@ describe('commands', () => {
data: fakeDownloadStream, data: fakeDownloadStream,
})); }));
const {name: tmpDirName} = dirSync({
unsafeCleanup: true,
});
const dest = `${tmpDirName}/flipperTest`; const dest = `${tmpDirName}/flipperTest`;
const fakeDownloadURL = 'https://flipper.rocks'; const fakeDownloadURL = 'https://flipper.rocks';
const fakeUuid = 'flipper42'; const fakeUuid = 'flipper42';
jest.spyOn(uuid, 'v4').mockImplementation(() => fakeUuid); jest.spyOn(uuid, 'v4').mockImplementation(() => fakeUuid);
await commandDownloadFileStart(fakeDownloadURL, dest, { await commandDownloadFileStart(fakeDownloadURL, dest);
overwrite: true,
});
const lastFileUpdateCalled = new Promise((resolve) => const lastFileUpdateCalled = new Promise((resolve) =>
emit.mockImplementationOnce(resolve), emit.mockImplementationOnce(resolve),
@@ -159,7 +159,7 @@ describe('commands', () => {
}); });
}); });
test.skip('rejects "complete" promise if writeable stream errors', async () => { test('rejects "complete" promise if writeable stream errors', async () => {
const fakeDownloadStream = new MemoryStream(); const fakeDownloadStream = new MemoryStream();
const fakeFileSize = 10; const fakeFileSize = 10;
const fakeHeaders = { const fakeHeaders = {
@@ -175,18 +175,12 @@ describe('commands', () => {
data: fakeDownloadStream, data: fakeDownloadStream,
})); }));
const {name: tmpDirName, removeCallback: removeTmpDir} = dirSync({
unsafeCleanup: true,
});
const dest = `${tmpDirName}/flipperTest`;
const fakeDownloadURL = 'https://flipper.rocks'; const fakeDownloadURL = 'https://flipper.rocks';
const fakeUuid = 'flipper42'; const fakeUuid = 'flipper42';
jest.spyOn(uuid, 'v4').mockImplementation(() => fakeUuid); jest.spyOn(uuid, 'v4').mockImplementation(() => fakeUuid);
await commandDownloadFileStart(fakeDownloadURL, dest, { // We provide an invalid path to force write stream to fail
overwrite: true, await commandDownloadFileStart(fakeDownloadURL, '');
});
const lastFileUpdateCalled = new Promise<void>((resolve) => const lastFileUpdateCalled = new Promise<void>((resolve) =>
emit.mockImplementation( emit.mockImplementation(
@@ -194,10 +188,7 @@ describe('commands', () => {
), ),
); );
// We remove the end file to cause an error
removeTmpDir();
fakeDownloadStream.write('Obi'); fakeDownloadStream.write('Obi');
await lastFileUpdateCalled; await lastFileUpdateCalled;
expect(emit).toBeCalledTimes(2); expect(emit).toBeCalledTimes(2);
@@ -212,7 +203,7 @@ describe('commands', () => {
downloaded: 3, downloaded: 3,
totalSize: fakeFileSize, totalSize: fakeFileSize,
status: 'error', status: 'error',
message: expect.stringContaining('ENOENT'), message: expect.anything(),
stack: expect.anything(), stack: expect.anything(),
}); });
}); });