Skip to content

Commit fdfc7e0

Browse files
author
Akos Kitta
committed
test: use raw core index-update for the tests
It should make integration tests more resilient on the Windows CI. From now on, tests are not starting a daemon to initialize the `directories.data` folder for the test suites but rely on the raw command. It is required to avoid spawning the discovery processes, which cannot be terminated on Windows while the daemon is up and running. Closes #2059 Signed-off-by: Akos Kitta <[email protected]>
1 parent 36e2092 commit fdfc7e0

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

Diff for: arduino-ide-extension/src/test/node/core-client-provider.slow-test.ts

+27-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { DisposableCollection } from '@theia/core/lib/common/disposable';
2-
import { waitForEvent } from '@theia/core/lib/common/promise-util';
32
import type { MaybePromise } from '@theia/core/lib/common/types';
43
import { FileUri } from '@theia/core/lib/node/file-uri';
54
import { Container } from '@theia/core/shared/inversify';
@@ -16,6 +15,7 @@ import { ArduinoDaemonImpl } from '../../node/arduino-daemon-impl';
1615
import { CLI_CONFIG, DefaultCliConfig } from '../../node/cli-config';
1716
import { BoardListRequest } from '../../node/cli-protocol/cc/arduino/cli/commands/v1/board_pb';
1817
import { CoreClientProvider } from '../../node/core-client-provider';
18+
import { spawnCommand } from '../../node/exec-util';
1919
import { ConfigDirUriProvider } from '../../node/theia/env-variables/env-variables-server';
2020
import { ErrnoException } from '../../node/utils/errors';
2121
import {
@@ -177,10 +177,9 @@ describe('core-client-provider', () => {
177177
boardsPackages.filter(({ id }) => id === 'teensy:avr').length
178178
).to.be.equal(1);
179179
};
180-
const configDirPath = await prepareTestConfigDir(
181-
{ board_manager: { additional_urls: additionalUrls } },
182-
({ boardsService }) => assertTeensyAvailable(boardsService)
183-
);
180+
const configDirPath = await prepareTestConfigDir({
181+
board_manager: { additional_urls: additionalUrls },
182+
});
184183
const thirdPartyPackageIndexPath = join(
185184
configDirPath,
186185
'data',
@@ -273,27 +272,31 @@ async function assertFunctionalCli(
273272
* the config folder.
274273
*/
275274
async function prepareTestConfigDir(
276-
configOverrides: Partial<DefaultCliConfig> = {},
277-
otherExpect?: (services: Services) => MaybePromise<void>
275+
configOverrides: Partial<DefaultCliConfig> = {}
278276
): Promise<string> {
279-
const toDispose = new DisposableCollection();
280277
const params = { configDirPath: newTempConfigDirPath(), configOverrides };
281278
const container = await createContainer(params);
282-
try {
283-
await start(container, toDispose);
284-
await assertFunctionalCli(container, otherExpect);
285-
const configDirUriProvider =
286-
container.get<ConfigDirUriProvider>(ConfigDirUriProvider);
287-
return FileUri.fsPath(configDirUriProvider.configDirUri());
288-
} finally {
289-
const daemon = container.get<ArduinoDaemonImpl>(ArduinoDaemonImpl);
290-
// Wait for the daemon stop event. All subprocesses (such as `serial-discovery` and `mdns-discovery`) must terminate.
291-
// Otherwise, `EPERM: operation not permitted, unlink` is thrown on Windows when "corrupting" the `directories.data` folder for the tests.
292-
await Promise.all([
293-
waitForEvent(daemon.onDaemonStopped, 5_000),
294-
Promise.resolve(toDispose.dispose()),
295-
]);
296-
}
279+
const daemon = container.get<ArduinoDaemonImpl>(ArduinoDaemonImpl);
280+
const cliPath = await daemon.getExecPath();
281+
const configDirUriProvider =
282+
container.get<ConfigDirUriProvider>(ConfigDirUriProvider);
283+
const configDirPath = FileUri.fsPath(configDirUriProvider.configDirUri());
284+
await coreUpdateIndex(cliPath, configDirPath);
285+
return configDirPath;
286+
}
287+
288+
async function coreUpdateIndex(
289+
cliPath: string,
290+
configDirPath: string
291+
): Promise<void> {
292+
const cliConfigPath = join(configDirPath, 'arduino-cli.yaml');
293+
await fs.access(cliConfigPath);
294+
const stdout = await spawnCommand(
295+
cliPath,
296+
['core', 'update-index', '--config-file', cliConfigPath],
297+
(error) => console.error(error)
298+
);
299+
console.log(stdout);
297300
}
298301

299302
async function startCli(
@@ -312,15 +315,8 @@ async function startCli(
312315
throw err;
313316
}
314317
const container = await createContainer(configDirPath);
315-
await start(container, toDispose);
316-
return container;
317-
}
318-
319-
async function start(
320-
container: Container,
321-
toDispose: DisposableCollection
322-
): Promise<void> {
323318
await startDaemon(container, toDispose);
319+
return container;
324320
}
325321

326322
async function createContainer(

0 commit comments

Comments
 (0)