Skip to content

Commit

Permalink
4.3.3 support (#143)
Browse files Browse the repository at this point in the history
- Ignore fed guids on always present element ids when comparing imodels
in tests
- closeIModel() + closeFile()
- script to only update locked itwin deps
- bump locked itwin dev deps

---------

Co-authored-by: Michael Belousov <[email protected]>
  • Loading branch information
nick4598 and MichaelBelousov authored Jan 22, 2024
1 parent 7882d7b commit 625df9f
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 116 deletions.
4 changes: 3 additions & 1 deletion packages/performance-tests/test/iModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function setToStandalone(iModelPath: string) {
nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned); // standalone iModels should always have BriefcaseId unassigned
nativeDb.saveLocalValue("StandaloneEdit", JSON.stringify({ txns: true }));
nativeDb.saveChanges(); // save change to briefcaseId
nativeDb.closeIModel();
// handle cross-version usage of internal API
(nativeDb as any)?.closeIModel?.();
(nativeDb as any)?.closeFile?.();
}

export function generateTestIModel(iModelParam: IModelParams): TestIModel {
Expand Down
23 changes: 17 additions & 6 deletions packages/transformer/src/test/IModelTransformerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,18 @@ export async function assertIdentityTransformation(
// [IModelTransformerOptions.includeSourceProvenance]$(transformer) is set to true
classesToIgnoreMissingEntitiesOfInTarget = [...IModelTransformer.provenanceElementClasses, ...IModelTransformer.provenanceElementAspectClasses],
compareElemGeom = false,
ignoreFedGuidsOnAlwaysPresentElementIds = true,
}: {
expectedElemsOnlyInSource?: Partial<ElementProps>[];
/** before checking elements that are only in the source are correct, filter out elements of these classes */
classesToIgnoreMissingEntitiesOfInTarget?: typeof Entity[];
compareElemGeom?: boolean;
/** if true, ignores the fed guids present on always present elements (present even in an empty iModel!).
* That list includes the root subject (0x1), dictionaryModel (0x10) and the realityDataSourcesModel (0xe) */
ignoreFedGuidsOnAlwaysPresentElementIds?: boolean;
} = {}
) {
const alwaysPresentElementIds = new Set<Id64String>(["0x1", "0x10", "0xe"]);
const [remapElem, remapCodeSpec, remapAspect]
= remapper instanceof IModelTransformer
? [remapper.context.findTargetElementId.bind(remapper.context),
Expand Down Expand Up @@ -274,7 +279,8 @@ export async function assertIdentityTransformation(
// known cases for the prop expecting to have been changed by the transformation under normal circumstances
// - federation guid will be generated if it didn't exist
// - jsonProperties may include remapped ids
const propChangesAllowed = sourceElem.federationGuid === undefined || propName === "jsonProperties";
const propChangesAllowed = ((propName === "federationGuid" && (sourceElem.federationGuid === undefined || (ignoreFedGuidsOnAlwaysPresentElementIds && alwaysPresentElementIds.has(sourceElemId))))
|| propName === "jsonProperties");
if (prop.isNavigation) {
expect(sourceElem.classFullName).to.equal(targetElem.classFullName);
// some custom handled classes make it difficult to inspect the element props directly with the metadata prop name
Expand All @@ -295,11 +301,16 @@ export async function assertIdentityTransformation(
mappedRelationTargetInTargetId
);
} else if (!propChangesAllowed) {
// kept for conditional breakpoints
const _propEq = TestUtils.advancedDeepEqual(targetElem.asAny[propName], sourceElem.asAny[propName]);
expect(targetElem.asAny[propName]).to.deep.advancedEqual(
sourceElem.asAny[propName]
);
try {
expect(
(targetElem as any)[propName],
`${targetElem.id}[${propName}] didn't match ${sourceElem.id}[${propName}]`
).to.deep.advancedEqual((sourceElem as any)[propName]);
} catch (err) {
// for debugging broken tests
debugger; // eslint-disable-line no-debugger
throw err;
}
}
}
const quickClone = (obj: any) => JSON.parse(JSON.stringify(obj));
Expand Down
16 changes: 14 additions & 2 deletions packages/transformer/src/test/standalone/IModelTransformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,9 @@ describe("IModelTransformer", () => {
nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned); // standalone iModels should always have BriefcaseId unassigned
nativeDb.saveLocalValue("StandaloneEdit", JSON.stringify({ txns: true }));
nativeDb.saveChanges(); // save change to briefcaseId
nativeDb.closeIModel();
// handle cross-version usage of internal API
(nativeDb as any)?.closeIModel?.();
(nativeDb as any)?.closeFile?.();
}

it("biscore update is valid", async () => {
Expand All @@ -1108,7 +1110,9 @@ describe("IModelTransformer", () => {
// StandaloneDb.upgradeStandaloneSchemas is the suggested method to handle a profile upgrade but that will also upgrade
// the BisCore schema. This test is explicitly testing that the BisCore schema will be updated from the source iModel
const nativeDb = StandaloneDb.openDgnDb({path: targetDbPath}, OpenMode.ReadWrite, {profile: ProfileOptions.Upgrade, schemaLockHeld: true});
nativeDb.closeIModel();
// handle cross-version usage of internal API
(nativeDb as any)?.closeIModel?.();
(nativeDb as any)?.closeFile?.();
const targetDb = StandaloneDb.openFile(targetDbPath);

assert(
Expand All @@ -1135,11 +1139,19 @@ describe("IModelTransformer", () => {

/** gets a mapping of element ids to their invariant content */
async function getAllElementsInvariants(db: IModelDb, filterPredicate?: (element: Element) => boolean) {
// The set of element Ids where the fed guid should be ignored (since it can change between transforms).
const ignoreFedGuidElementIds = new Set<Id64String>([
IModel.rootSubjectId,
IModel.dictionaryId,
"0xe", // id of realityDataSourcesModel
]);
const result: Record<Id64String, any> = {};
// eslint-disable-next-line deprecation/deprecation
for await (const row of db.query("SELECT * FROM bis.Element", undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
if (!filterPredicate || filterPredicate(db.elements.getElement(row.id))) {
const { lastMod: _lastMod, ...invariantPortion } = row;
if (ignoreFedGuidElementIds.has(row.id))
delete invariantPortion.federationGuid;
result[row.id] = invariantPortion;
}
}
Expand Down
Loading

0 comments on commit 625df9f

Please sign in to comment.