From 3a36f4567676830c2ad56eed27e06328ff5d1420 Mon Sep 17 00:00:00 2001 From: myarmolinsky Date: Fri, 18 Oct 2024 11:07:24 -0400 Subject: [PATCH] Test fix for `image-manager.spec.ts` flakiness Change-type: patch --- .../utils/image-manager/image-manager.spec.ts | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/tests/utils/image-manager/image-manager.spec.ts b/tests/utils/image-manager/image-manager.spec.ts index 22494ad849..f3c377493f 100644 --- a/tests/utils/image-manager/image-manager.spec.ts +++ b/tests/utils/image-manager/image-manager.spec.ts @@ -2,7 +2,7 @@ import * as stream from 'stream'; import { AssertionError, expect } from 'chai'; import { stub } from 'sinon'; import * as tmp from 'tmp'; -import { delay } from '../../utils'; +// import { delay } from '. ./../utils'; import * as fs from 'fs'; import * as fsAsync from 'fs/promises'; import * as stringToStream from 'string-to-stream'; @@ -79,53 +79,53 @@ describe('image-manager', function () { }); // Skipping test because we keep getting `Cache image` instead of `Download image` - describe.skip('given a valid download endpoint', function () { - beforeEach(function () { - this.osDownloadStub = stub(balena.models.os, 'download'); - this.osDownloadStub.returns( - Promise.resolve(stringToStream('Download image')), - ); - }); - - afterEach(function () { - this.osDownloadStub.restore(); - }); - - it('should eventually become a readable stream of the download image and save a backup copy', function (done) { - void imageManager.getStream('raspberry-pi').then((stream) => { - let result = ''; - - stream.on('data', (chunk) => (result += chunk)); - - stream.on('end', async () => { - expect(result).to.equal('Download image'); - const contents = await fsAsync.readFile(this.image.name, { - encoding: 'utf8', - }); - expect(contents).to.equal('Download image'); - done(); - }); - }); - }); - - it('should be able to read from the stream after a slight delay', function (done) { - void imageManager.getStream('raspberry-pi').then(async (s) => { - await delay(200); - - const pass = new stream.PassThrough(); - s.pipe(pass); - - let result = ''; - - pass.on('data', (chunk) => (result += chunk)); - - pass.on('end', function () { - expect(result).to.equal('Download image'); - done(); - }); - }); - }); - }); + // describe.skip('given a valid download endpoint', function () { + // beforeEach(function () { + // this.osDownloadStub = stub(balena.models.os, 'download'); + // this.osDownloadStub.returns( + // Promise.resolve(stringToStream('Download image')), + // ); + // }); + + // afterEach(function () { + // this.osDownloadStub.restore(); + // }); + + // it('should eventually become a readable stream of the download image and save a backup copy', function (done) { + // void imageManager.getStream('raspberry-pi').then((stream) => { + // let result = ''; + + // stream.on('data', (chunk) => (result += chunk)); + + // stream.on('end', async () => { + // expect(result).to.equal('Download image'); + // const contents = await fsAsync.readFile(this.image.name, { + // encoding: 'utf8', + // }); + // expect(contents).to.equal('Download image'); + // done(); + // }); + // }); + // }); + + // it('should be able to read from the stream after a slight delay', function (done) { + // void imageManager.getStream('raspberry-pi').then(async (s) => { + // await delay(200); + + // const pass = new stream.PassThrough(); + // s.pipe(pass); + + // let result = ''; + + // pass.on('data', (chunk) => (result += chunk)); + + // pass.on('end', function () { + // expect(result).to.equal('Download image'); + // done(); + // }); + // }); + // }); + // }); describe('given a failing download', function () { beforeEach(function () { @@ -158,6 +158,7 @@ describe('image-manager', function () { ); }) .catch((err) => { + console.info('*** err', err); if (err.code !== 'ENOENT') { throw err; }