Skip to content

Commit f87711b

Browse files
author
Akos Kitta
committed
fix(test): integration tests are more resilient
- queued PUT/DELETE requests to make the test timeout happy - reduced the offset to 1/5th. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent b3f3616 commit f87711b

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

arduino-ide-extension/src/test/browser/create-api.test.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { assert, expect } from 'chai';
77
import fetch from 'cross-fetch';
88
import { rejects } from 'node:assert';
99
import { posix } from 'node:path';
10+
import PQueue from 'p-queue';
1011
import queryString from 'query-string';
1112
import { v4 } from 'uuid';
1213
import { ArduinoPreferences } from '../../browser/arduino-preferences';
@@ -50,6 +51,11 @@ describe('create-api', () => {
5051
await cleanAllSketches();
5152
});
5253

54+
afterEach(async function () {
55+
this.timeout(timeout);
56+
await cleanAllSketches();
57+
});
58+
5359
function createContainer(accessToken: string): Container {
5460
const container = new Container({ defaultScope: 'Singleton' });
5561
container.load(
@@ -126,13 +132,14 @@ describe('create-api', () => {
126132

127133
async function cleanAllSketches(): Promise<void> {
128134
let sketches = await createApi.sketches();
129-
// Cannot delete the sketches with `await Promise.all` as all delete promise successfully resolve, but the sketch is not deleted from the server.
130-
await sketches
131-
.map(({ path }) => createApi.deleteSketch(path))
132-
.reduce(async (acc, curr) => {
133-
await acc;
134-
return curr;
135-
}, Promise.resolve());
135+
const deleteExecutionQueue = new PQueue({
136+
concurrency: 5,
137+
autoStart: true,
138+
});
139+
sketches.forEach(({ path }) =>
140+
deleteExecutionQueue.add(() => createApi.deleteSketch(path))
141+
);
142+
await deleteExecutionQueue.onIdle();
136143
sketches = await createApi.sketches();
137144
expect(sketches).to.be.empty;
138145
}
@@ -348,19 +355,23 @@ describe('create-api', () => {
348355
diff < 0 ? '<' : diff > 0 ? '>' : '='
349356
} limit)`, async () => {
350357
const content = 'void setup(){} void loop(){}';
351-
const maxLimit = 50; // https://github.com/arduino/arduino-ide/pull/875
358+
const maxLimit = 10;
352359
const sketchCount = maxLimit + diff;
353360
const sketchNames = [...Array(sketchCount).keys()].map(() => v4());
354361

355-
await sketchNames
356-
.map((name) => createApi.createSketch(toPosix(name), content))
357-
.reduce(async (acc, curr) => {
358-
await acc;
359-
return curr;
360-
}, Promise.resolve() as Promise<unknown>);
362+
const createExecutionQueue = new PQueue({
363+
concurrency: 5,
364+
autoStart: true,
365+
});
366+
sketchNames.forEach((name) =>
367+
createExecutionQueue.add(() =>
368+
createApi.createSketch(toPosix(name), content)
369+
)
370+
);
371+
await createExecutionQueue.onIdle();
361372

362373
createApi.resetRequestRecording();
363-
const sketches = await createApi.sketches();
374+
const sketches = await createApi.sketches(maxLimit);
364375
const allRequests = createApi.requestRecording.slice();
365376

366377
expect(sketches.length).to.be.equal(sketchCount);

0 commit comments

Comments
 (0)