From 98506874915959394f5baf762b82ca6f6dc7963d Mon Sep 17 00:00:00 2001 From: andrea rota Date: Tue, 13 Sep 2022 12:11:06 +0100 Subject: [PATCH] allow to pass through retries param to tune awaiting for piece importer to finish --- .../features-specification.legacy-piece-importer.ts | 5 ++++- ...res-specification.legacy-piece-importer.e2e-spec.ts | 10 +++++----- .../src/legacy-project-import-piece-processor.port.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/apps/geoprocessing/src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer.ts b/api/apps/geoprocessing/src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer.ts index 3ad767f728..2f33b86f2d 100644 --- a/api/apps/geoprocessing/src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer.ts +++ b/api/apps/geoprocessing/src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer.ts @@ -291,6 +291,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter specRows: PropSpecDatRow[], projectId: string, scenarioId: string, + retries?: number, ): Promise { const featureIdByIntegerId = await this.getFeatureIdByIntegerIdMap( projectId, @@ -330,6 +331,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter const specificationResult = await this.waitUntilSpecificationEnds( scenarioId, + retries ); if (isLeft(specificationResult)) { this.logAndThrow( @@ -395,6 +397,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter async run( input: LegacyProjectImportJobInput, + retries?: number, ): Promise { const { files, projectId, scenarioId } = input; @@ -415,7 +418,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter } const specRows = this.getPropSpecRows(specRowsOrError, puvsprRowsOrError); - await this.runSpecification(specRows, projectId, scenarioId); + await this.runSpecification(specRows, projectId, scenarioId, retries); await this.updateScenarioFeaturesData(specRows, scenarioId); return input; diff --git a/api/apps/geoprocessing/test/integration/legacy-project-import/features-specification.legacy-piece-importer.e2e-spec.ts b/api/apps/geoprocessing/test/integration/legacy-project-import/features-specification.legacy-piece-importer.e2e-spec.ts index 7a2b534d5f..f358b8e521 100644 --- a/api/apps/geoprocessing/test/integration/legacy-project-import/features-specification.legacy-piece-importer.e2e-spec.ts +++ b/api/apps/geoprocessing/test/integration/legacy-project-import/features-specification.legacy-piece-importer.e2e-spec.ts @@ -229,7 +229,7 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => { .ThenASpecificationDidntFinishErrorShouldBeThrown(); }, timeoutForTestsThatNeedToCheckSpecificationJobStatus); - it(`fails when specification async job timeouts`, async () => { + it(`fails when specification async job times out`, async () => { const specDatFileType = LegacyProjectImportFileType.SpecDat; const puvsprDatFileType = LegacyProjectImportFileType.PuvsprDat; @@ -249,7 +249,7 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => { await fixtures .WhenPieceImporterIsInvoked(job) - .AndSpecificationProcessTimeouts() + .AndSpecificationProcessTimesOut() .ThenASpecificationDidntFinishErrorShouldBeThrown(); }, timeoutForTestsThatNeedToCheckSpecificationJobStatus * 2); @@ -685,7 +685,7 @@ const getFixtures = async () => { }), ); }, - WhenPieceImporterIsInvoked: (input: LegacyProjectImportJobInput) => { + WhenPieceImporterIsInvoked: (input: LegacyProjectImportJobInput, retries?: number) => { return { ThenADatFileNotFoundErrorShouldBeThrown: async ( file: LegacyProjectImportFileType, @@ -732,10 +732,10 @@ const getFixtures = async () => { }, }; }, - AndSpecificationProcessTimeouts: () => { + AndSpecificationProcessTimesOut: () => { return { ThenASpecificationDidntFinishErrorShouldBeThrown: async () => { - await expect(sut.run(input)).rejects.toThrow( + await expect(sut.run(input, retries)).rejects.toThrow( /specification didn't finish: specification timeout/gi, ); }, diff --git a/api/libs/legacy-project-import/src/legacy-project-import-piece-processor.port.ts b/api/libs/legacy-project-import/src/legacy-project-import-piece-processor.port.ts index cad0869cc4..9a2f547f2d 100644 --- a/api/libs/legacy-project-import/src/legacy-project-import-piece-processor.port.ts +++ b/api/libs/legacy-project-import/src/legacy-project-import-piece-processor.port.ts @@ -1,7 +1,7 @@ import { LegacyProjectImportPiece } from './domain/legacy-project-import-piece'; export abstract class LegacyProjectImportPieceProcessor { - abstract run(input: I): Promise; + abstract run(input: I, retries?: number): Promise; abstract isSupported(piece: LegacyProjectImportPiece): boolean; }