From ee4e668f0df5b25f076917eb5ebc46424a564f08 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 May 2023 12:43:10 +0200 Subject: [PATCH 1/2] config-loader: avoid setTimeout in file watching tests Signed-off-by: Patrik Oldsberg --- .../src/sources/FileConfigSource.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/config-loader/src/sources/FileConfigSource.test.ts b/packages/config-loader/src/sources/FileConfigSource.test.ts index c6980006c0..6479fb77c0 100644 --- a/packages/config-loader/src/sources/FileConfigSource.test.ts +++ b/packages/config-loader/src/sources/FileConfigSource.test.ts @@ -64,9 +64,10 @@ describe('FileConfigSource', () => { const source = FileConfigSource.create({ path: tmp.resolve('a.yaml') }); - setTimeout(() => { - tmp.write('a.yaml', 'a: 2'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('a.yaml', 'a: 2')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: 1 }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -130,9 +131,10 @@ describe('FileConfigSource', () => { substitutionFunc: async name => (name === 'MY_VALUE' ? '6' : '7'), }); - setTimeout(() => { - tmp.write('x.yaml', '${MY_OTHER_VALUE}'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('x.yaml', '${MY_OTHER_VALUE}')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '6' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -150,9 +152,10 @@ describe('FileConfigSource', () => { path: tmp.resolve('a.yaml'), }); - setTimeout(() => { - tmp.write('x.txt', '9'); - }, 10); + source + .readConfigData() + .next() + .then(() => tmp.write('x.txt', '9')); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '8' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], From 29820706548105dad0c089256b361a6f8b3b9aed Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 May 2023 13:10:33 +0200 Subject: [PATCH 2/2] config-loader: back to setTimeout with bigger margin Signed-off-by: Patrik Oldsberg --- .../src/sources/FileConfigSource.test.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/config-loader/src/sources/FileConfigSource.test.ts b/packages/config-loader/src/sources/FileConfigSource.test.ts index 6479fb77c0..61cdeed272 100644 --- a/packages/config-loader/src/sources/FileConfigSource.test.ts +++ b/packages/config-loader/src/sources/FileConfigSource.test.ts @@ -64,10 +64,9 @@ describe('FileConfigSource', () => { const source = FileConfigSource.create({ path: tmp.resolve('a.yaml') }); - source - .readConfigData() - .next() - .then(() => tmp.write('a.yaml', 'a: 2')); + setTimeout(() => { + tmp.write('a.yaml', 'a: 2'); + }, 100); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: 1 }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -131,10 +130,9 @@ describe('FileConfigSource', () => { substitutionFunc: async name => (name === 'MY_VALUE' ? '6' : '7'), }); - source - .readConfigData() - .next() - .then(() => tmp.write('x.yaml', '${MY_OTHER_VALUE}')); + setTimeout(() => { + tmp.write('x.yaml', '${MY_OTHER_VALUE}'); + }, 100); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '6' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }], @@ -152,10 +150,9 @@ describe('FileConfigSource', () => { path: tmp.resolve('a.yaml'), }); - source - .readConfigData() - .next() - .then(() => tmp.write('x.txt', '9')); + setTimeout(() => { + tmp.write('x.txt', '9'); + }, 100); await expect(readN(source, 2)).resolves.toEqual([ [{ data: { a: '8' }, context: 'a.yaml', path: tmp.resolve('a.yaml') }],