Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fix for image-manager.spec.ts flakiness #2863

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/utils/image-manager/image-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,47 +129,63 @@ describe('image-manager', function () {

describe('given a failing download', function () {
beforeEach(function () {
console.info('*** 1');
this.osDownloadStream = new stream.PassThrough();
console.info('*** 2');
this.osDownloadStub = stub(balena.models.os, 'download');
console.info('*** 3');
this.osDownloadStub.returns(Promise.resolve(this.osDownloadStream));
console.info('*** 4');
});

afterEach(function () {
console.info('*** 5');
this.osDownloadStub.restore();
console.info('*** 6');
});

it('should clean up the in progress cached stream if an error occurs', function (done) {
if (os.platform() === 'win32') {
// Skipping test on Windows because we get `EPERM: operation not permitted, rename` for `getImageWritableStream` on the windows runner
this.skip();
}
console.info('*** 7');
void imageManager.getStream('raspberry-pi').then((stream) => {
console.info('*** 8');
stream.on('data', () => {
// After the first chunk, error
console.info('*** 9');
return this.osDownloadStream.emit('error');
});
console.info('*** 10');

stream.on('error', async () => {
console.info('*** 11');
const contents = await fsAsync
.stat(this.image.name + '.inprogress')
.then(function () {
console.info('*** 12');
throw new AssertionError(
'Image cache should be deleted on failure',
);
})
.catch((err) => {
console.info('*** 13 err', err);
if (err.code !== 'ENOENT') {
throw err;
}
return fsAsync.readFile(this.image.name, {
encoding: 'utf8',
});
});
console.info('*** 14');
expect(contents).to.equal('Cache image');
done();
});
console.info('*** 15');

stringToStream('Download image').pipe(this.osDownloadStream);
console.info('*** 16');
});
});
});
Expand Down
Loading