Skip to content

Commit 8907b26

Browse files
authored
Fixed imodel populate calling imodel connection auth when not appropriate and not checking for errors. (#139)
* Fixed imodel:connection:auth being called in populate when using service client. Moved out setup for running tests with a specific client to utils/mocha-global-setup-*.ts. Added seperate launch configurations for launching active test with a specific client. * Added a check for failures to imodel populate command. Added a few tests for imodel populate command. Moved current used client notification to integration-tests/utils/mocha-global-setup-*.ts. A few misc fixes. * Increased default test timeout to 2min. * Removed tests skips from imodel populate tests. Added some debug logging to named-version.ts before() hook. * Debug changes. * Debug changes. * Fixed a few issues in tests. * Updated a test.
1 parent 607a88f commit 8907b26

19 files changed

Lines changed: 176 additions & 110 deletions

.vscode/launch.json

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
"--forbid-only",
4343
"--timeout",
4444
"999999",
45-
"integration-tests/main-cases/*.test.ts"
45+
"integration-tests/main-cases/*.test.ts",
4646
],
4747
"console": "integratedTerminal",
4848
"internalConsoleOptions": "neverOpen"
4949
},
5050
{
51-
"name": "Debug Active Test",
51+
"name": "Debug Active Test (Service Client)",
5252
"skipFiles": [
5353
"<node_internals>/**"
5454
],
@@ -59,10 +59,31 @@
5959
"--forbid-only",
6060
"--timeout",
6161
"999999",
62-
"${file}"
62+
"${file}",
63+
"--require",
64+
"integration-tests/utils/mocha-global-setup-service.ts"
6365
],
6466
"console": "integratedTerminal",
6567
"internalConsoleOptions": "neverOpen"
66-
}
68+
},
69+
{
70+
"name": "Debug Active Test (Native Client)",
71+
"skipFiles": [
72+
"<node_internals>/**"
73+
],
74+
"type": "node",
75+
"request": "launch",
76+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha",
77+
"args": [
78+
"--forbid-only",
79+
"--timeout",
80+
"999999",
81+
"${file}",
82+
"--require",
83+
"integration-tests/utils/mocha-global-setup-native.ts"
84+
],
85+
"console": "integratedTerminal",
86+
"internalConsoleOptions": "neverOpen"
87+
},
6788
]
6889
}

integration-tests/imodel/named-version.test.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,35 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IModel, NamedVersion } from '@itwin/imodels-client-management';
7-
import { ITwin } from '@itwin/itwins-client';
6+
import { NamedVersion } from '@itwin/imodels-client-management';
87
import { runCommand } from '@oclif/test';
98
import { expect } from 'chai';
109

1110
import { changeset } from '../../src/services/changed-elements-client/tracking';
12-
import { createFile, createIModel, createITwin, getRootFolderId } from '../utils/helpers';
11+
import { createIModel, createITwin } from '../utils/helpers';
1312
import { resultResponse } from '../utils/result-response';
1413
import runSuiteIfMainModule from '../utils/run-suite-if-main-module';
1514

1615
const tests = () => describe('named-version', () => {
1716
const testITwinName = 'ITwinCLI_IntegrationTestITwin_iModelNamedVersion';
1817
const testIModelName = 'ITwinCLI_IntegrationTestIModel_iModelNamedVersion';
19-
const testFileName = 'test.zip';
20-
const testFilePath = 'integration-tests/test.zip';
18+
const testFilePath = 'examples/datasets/ExtonCampus.dgn';
2119
let testIModelId: string;
2220
let testITwinId: string;
2321

2422
before(async function() {
2523
this.timeout(30 * 60 * 1000);
2624

27-
const filteredITwins = await runCommand<ITwin[]>(`itwin list --name ${testITwinName}`);
28-
expect(filteredITwins.result).to.not.be.undefined
25+
const testITwin = await createITwin(testITwinName, 'Thing', 'Asset');
26+
testITwinId = testITwin.id as string;
27+
const testIModel = await createIModel(testIModelName, testITwinId);
28+
testIModelId = testIModel.id;
2929

30-
if(filteredITwins.result!.length === 0) {
31-
const testITwin = await createITwin(testITwinName, 'Thing', 'Asset');
32-
testITwinId = testITwin.id as string;
33-
const testIModel = await createIModel(testIModelName, testITwinId);
34-
testIModelId = testIModel.id;
30+
await runCommand<resultResponse>(`changed-elements enable --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
3531

36-
await runCommand<resultResponse>(`changed-elements enable --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
37-
38-
const rootFolderId = await getRootFolderId(testITwinId);
39-
await createFile(rootFolderId, testFileName, testFilePath);
40-
41-
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID`);
42-
expect(result.result).to.have.property('iModelId', testIModelId);
43-
expect(result.result).to.have.property('iTwinId', testITwinId);
44-
}
45-
else {
46-
testITwinId = filteredITwins.result![0].id!;
47-
const iModels = await runCommand<IModel[]>(`imodel list --itwin-id ${testITwinId}`);
48-
expect(iModels.result).to.not.be.undefined;
49-
expect(iModels.result?.length).to.be.equal(1);
50-
testIModelId = iModels.result![0].id;
51-
}
32+
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type MSTN`);
33+
expect(result.result).to.have.property('iModelId', testIModelId);
34+
expect(result.result).to.have.property('iTwinId', testITwinId);
5235
});
5336

5437
after(async () => {
@@ -62,7 +45,7 @@ const tests = () => describe('named-version', () => {
6245
it('should create a new named version with specified changeset', async () => {
6346
const { result: changesets} = await runCommand<changeset[]>(`changed-elements changesets --imodel-id ${testIModelId} --itwin-id ${testITwinId}`);
6447
expect(changesets).to.not.be.undefined;
65-
expect(changesets!.length).to.be.equal(4);
48+
expect(changesets!.length).to.be.equal(15);
6649

6750
const response = await runCommand<NamedVersion>(`imodel named-version create --imodel-id ${testIModelId} --changeset-id ${changesets![0].id} -n "Version 1.0" -d "Some description of the version"`);
6851
expect(response.result).to.not.be.undefined;

integration-tests/imodel/populate.test.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
import { runCommand } from '@oclif/test';
77
import { expect } from 'chai';
88

9-
import { createFile, createIModel, createITwin, getRootFolderId } from '../utils/helpers';
9+
import { populateResponse} from '../../src/commands/imodel/populate';
10+
import { executionResult } from '../../src/services/synchronizationClient/models/execution-result';
11+
import { executionState } from '../../src/services/synchronizationClient/models/execution-state';
12+
import { storageConnection } from '../../src/services/synchronizationClient/models/storage-connection';
13+
import { storageRun } from '../../src/services/synchronizationClient/models/storage-run';
14+
import { createIModel, createITwin } from '../utils/helpers';
1015
import runSuiteIfMainModule from '../utils/run-suite-if-main-module';
1116

1217
const tests = () => describe('populate', () => {
13-
const testFileName = 'test.zip';
14-
const testFilePath = 'integration-tests/test.zip';
15-
let testFileId: string;
18+
const failingTestFilePath = 'integration-tests/test.zip'
19+
const testFilePath = 'examples/datasets/ExtonCampus.dgn';
20+
1621
let testIModelId: string;
1722
let testITwinId: string;
1823

@@ -21,24 +26,66 @@ const tests = () => describe('populate', () => {
2126
testITwinId = testITwin.id!;
2227
const testIModel = await createIModel(`cli-imodel-integration-test-${new Date().toISOString()}`, testITwinId);
2328
testIModelId = testIModel.id!;
24-
const rootFolderId = await getRootFolderId(testITwinId);
25-
const testFile = await createFile(rootFolderId, testFileName, testFilePath);
26-
testFileId = testFile.id!;
2729
});
2830

2931
after(async () => {
30-
const { result: fileDeleteResult } = await runCommand(`storage file delete --file-id ${testFileId}`);
3132
const { result: iModelDeleteResult } = await runCommand(`imodel delete --imodel-id ${testIModelId}`);
3233
const { result: iTwinDeleteResult } = await runCommand(`itwin delete --itwin-id ${testITwinId}`);
3334

34-
expect(fileDeleteResult).to.have.property('result', 'deleted');
3535
expect(iModelDeleteResult).to.have.property('result', 'deleted');
3636
expect(iTwinDeleteResult).to.have.property('result', 'deleted');
3737
});
3838

3939
it('should populate the iModel with the uploaded file', async () => {
40-
const result = await runCommand(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID`);
41-
expect(result.result).to.have.property('iModelId', testIModelId);
40+
const { result: populateResult } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type MSTN`);
41+
expect(populateResult).to.not.be.undefined;
42+
expect(populateResult!.iTwinId).to.be.equal(testITwinId);
43+
expect(populateResult!.iModelId).to.be.equal(testIModelId);
44+
expect(populateResult!.summary).to.not.be.undefined;
45+
expect(populateResult!.summary.length).to.be.equal(1);
46+
expect(populateResult!.summary[0].connectionId).to.not.be.undefined;
47+
expect(populateResult!.summary[0].runId).to.not.be.undefined;
48+
49+
const {connectionId, runId} = populateResult!.summary[0];
50+
const { result: infoResult } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
51+
expect(infoResult?.state).to.be.equal(executionState.COMPLETED);
52+
expect(infoResult?.result).to.be.equal(executionResult.SUCCESS);
53+
}).timeout(30 * 60 * 1000);
54+
55+
it('should populate the iModel with the uploaded file (no-wait flag with polling)', async () => {
56+
const { result: populateResult } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${testFilePath} --connector-type SPPID --no-wait`);
57+
expect(populateResult).to.not.be.undefined;
58+
expect(populateResult!.iTwinId).to.be.equal(testITwinId);
59+
expect(populateResult!.iModelId).to.be.equal(testIModelId);
60+
expect(populateResult!.summary).to.not.be.undefined;
61+
expect(populateResult!.summary.length).to.be.equal(1);
62+
expect(populateResult!.summary[0].connectionId).to.not.be.undefined;
63+
expect(populateResult!.summary[0].runId).to.not.be.undefined;
64+
65+
const {connectionId, runId} = populateResult!.summary[0];
66+
let { result: infoResult } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
67+
while(infoResult?.state !== "Completed") {
68+
// eslint-disable-next-line no-await-in-loop
69+
await new Promise(r => {setTimeout(r, 10_000)});
70+
71+
// eslint-disable-next-line no-await-in-loop
72+
const { result } = await runCommand<storageRun>(`imodel connection run info -c ${connectionId} --connection-run-id ${runId}`);
73+
infoResult = result;
74+
}
75+
76+
expect(infoResult?.state).to.be.equal(executionState.COMPLETED);
77+
expect(infoResult?.result).to.be.equal(executionResult.SUCCESS);
78+
}).timeout(30 * 60 * 1000);
79+
80+
it('should return an error message if synchronization run completes with a non-success state', async () => {
81+
const { error: populateError } = await runCommand<populateResponse>(`imodel populate --imodel-id ${testIModelId} --file ${failingTestFilePath} --connector-type IFC`);
82+
expect(populateError).to.not.be.undefined;
83+
expect(populateError?.message).to.match(/Synchronization run .*? resulted in an error. Run 'itp imodel connection run info --connection-id .*? --connection-run-id .*?' for more info./);
84+
85+
const command = populateError?.message.match(/imodel connection run info --connection-id .*? --connection-run-id .*?'/)![0]?.slice(0,-1);
86+
const { result: infoResult } = await runCommand<storageConnection>(command!);
87+
expect(infoResult).to.not.be.undefined;
88+
expect(infoResult?.error).to.not.be.null;
4289
}).timeout(30 * 60 * 1000);
4390
});
4491

integration-tests/main-cases/native-client-parallel/imodel-connection-run.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { runCommand } from '@oclif/test';
7-
86
import iModelConnectionRunTests from '../../imodel/connection/run.test';
9-
import { nativeLoginToCli } from '../../utils/helpers';
107

118
describe('Native Client Tests (imodel connection run)', async () => {
12-
before(async function() {
13-
this.timeout(5 * 60 * 1000);
14-
await nativeLoginToCli();
15-
await runCommand(`imodel connection auth`);
16-
})
17-
189
iModelConnectionRunTests();
1910
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import iModelNamedVersionTests from '../../imodel/named-version.test';
7+
8+
describe('Native Client Tests (imodel named-version)', async () => {
9+
iModelNamedVersionTests();
10+
});

integration-tests/main-cases/native-client-parallel/populate.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import iModelNamedVersionTests from '../../imodel/named-version.test';
76
import iModelPopulateTests from '../../imodel/populate.test';
8-
import { nativeLoginToCli } from '../../utils/helpers';
97

108
describe('Native Client Tests (imodel populate)', async () => {
11-
before(async function() {
12-
this.timeout(5 * 60 * 1000);
13-
await nativeLoginToCli();
14-
})
15-
16-
iModelNamedVersionTests();
179
iModelPopulateTests();
1810
});

integration-tests/main-cases/native-client-parallel/short-running.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import accessControlNativeTests from '../../access-control-native/access-control-native.test'
7-
import { nativeLoginToCli } from '../../utils/helpers';
87
import sharedQuickUseCasesParallel from '../shared-quick-use-cases-parallel';
98

109
describe('Native Client Tests', async () => {
11-
before(async function() {
12-
this.timeout(5 * 60 * 1000);
13-
await nativeLoginToCli();
14-
})
15-
1610
accessControlNativeTests();
1711
sharedQuickUseCasesParallel();
18-
1912
});

integration-tests/main-cases/native-client-serial.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import iModelConnectionAuthTests from '../imodel-native/connection/auth.test'
88
import { nativeLoginToCli } from '../utils/helpers';
99

1010
describe('Native Client Tests (serial)', async () => {
11-
before(async () => {
12-
await nativeLoginToCli();
13-
})
14-
1511
describe('Authentication Integration Tests', async () => {
1612
after(async () => {
1713
await nativeLoginToCli();

integration-tests/main-cases/service-client-parallel/imodel-connection-run.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import iModelConnectionRunTests from '../../imodel/connection/run.test';
7-
import { logoutFromCLI } from '../../utils/helpers';
87

98
describe('Service Client Tests (imodel connection run)', async () => {
10-
before(async function() {
11-
this.timeout(5 * 60 * 1000);
12-
await logoutFromCLI();
13-
})
14-
159
iModelConnectionRunTests();
1610
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import iModelNamedVersionTests from '../../imodel/named-version.test';
7+
8+
describe('Service Client Tests (imodel named-version)', () => {
9+
iModelNamedVersionTests();
10+
});

0 commit comments

Comments
 (0)