Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Apr 21, 2024
1 parent c2e7bbf commit aab965d
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 105 deletions.
149 changes: 71 additions & 78 deletions packages/seed/src/commands/test/test-runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export declare namespace TestRunner {
}

export abstract class TestRunner {
private built: boolean = false;
private buildInvocation: Promise<void> | undefined;
protected readonly generator: GeneratorWorkspace;
protected readonly lock: Semaphore;
protected readonly taskContextFactory: TaskContextFactory;
Expand All @@ -98,24 +98,13 @@ export abstract class TestRunner {
* Runs the generator.
*/
public async run({ fixture, configuration }: TestRunner.RunArgs): Promise<TestRunner.TestResult> {
if (!this.built) {
await this.build();
this.built = true;
if (this.buildInvocation == undefined) {
this.buildInvocation = this.build();
}
await this.buildInvocation;

const metrics: TestRunner.TestCaseMetrics = {};

const fixtureConfig = this.generator.workspaceConfig.fixtures?.[fixture];
if (fixtureConfig == null) {
return {
type: "failure",
cause: "invalid-fixture",
message: `Fixture ${fixture} not found.`,
id: fixture,
metrics
};
}

const id = configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`;
const absolutePathToAPIDefinition = AbsoluteFilePath.of(
path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture)
Expand All @@ -138,76 +127,80 @@ export abstract class TestRunner {
}

taskContext.logger.debug("Acquiring lock...");
await this.lock.acquire();
taskContext.logger.info("Running generator...");
try {
const generationStopwatch = new Stopwatch();
generationStopwatch.start();
await this.runGenerator({
id,
fernWorkspace,
absolutePathToWorkspace: this.generator.absolutePathToWorkspace,
irVersion: this.generator.workspaceConfig.irVersion,
outputVersion: configuration?.outputVersion,
language: this.generator.workspaceConfig.language,
selectAudiences: configuration?.audiences,
fixture,
customConfig: configuration?.customConfig,
publishConfig: configuration?.publishConfig ?? undefined,
taskContext,
outputDir:
configuration == null
? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture))
: join(
this.generator.absolutePathToWorkspace,
RelativeFilePath.of(fixture),
RelativeFilePath.of(configuration.outputFolder)
),
outputMode: configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode,
outputFolder,
keepDocker: this.keepDocker,
publishMetadata: configuration?.publishMetadata ?? undefined
});
generationStopwatch.stop();
metrics.generationTime = generationStopwatch.duration();
} catch (error) {
return {
type: "failure",
cause: "generation",
id: fixture,
metrics
};
}

if (this.skipScripts) {
await this.lock.acquire();
taskContext.logger.info("Running generator...");
try {
const generationStopwatch = new Stopwatch();
generationStopwatch.start();
await this.runGenerator({
id,
fernWorkspace,
absolutePathToWorkspace: this.generator.absolutePathToWorkspace,
irVersion: this.generator.workspaceConfig.irVersion,
outputVersion: configuration?.outputVersion,
language: this.generator.workspaceConfig.language,
selectAudiences: configuration?.audiences,
fixture,
customConfig: configuration?.customConfig,
publishConfig: configuration?.publishConfig ?? undefined,
taskContext,
outputDir:
configuration == null
? join(this.generator.absolutePathToWorkspace, RelativeFilePath.of(fixture))
: join(
this.generator.absolutePathToWorkspace,
RelativeFilePath.of(fixture),
RelativeFilePath.of(configuration.outputFolder)
),
outputMode: configuration?.outputMode ?? this.generator.workspaceConfig.defaultOutputMode,
outputFolder,
keepDocker: this.keepDocker,
publishMetadata: configuration?.publishMetadata ?? undefined
});
generationStopwatch.stop();
metrics.generationTime = generationStopwatch.duration();
} catch (error) {
return {
type: "failure",
cause: "generation",
id: fixture,
metrics
};
}

if (this.skipScripts) {
return {
type: "success",
id: fixture,
metrics
};
}

const scriptStopwatch = new Stopwatch();
scriptStopwatch.start();

const scriptResponse = await this.scriptRunner.run({ taskContext, fixture, outputFolder });

scriptStopwatch.stop();
metrics.compileTime = scriptStopwatch.duration();

if (scriptResponse.type === "failure") {
return {
type: "failure",
cause: "compile",
id: fixture,
metrics
};
}
return {
type: "success",
id: fixture,
metrics
};
} finally {
this.lock.release();
}

const scriptStopwatch = new Stopwatch();
scriptStopwatch.start();

const scriptResponse = await this.scriptRunner.run({ taskContext, fixture, outputFolder });

scriptStopwatch.stop();
metrics.compileTime = scriptStopwatch.duration();

if (scriptResponse.type === "failure") {
return {
type: "failure",
cause: "compile",
id: fixture,
metrics
};
}
return {
type: "success",
id: fixture,
metrics
};
}

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions seed/go-sdk/basic-auth-environment-variables/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/circular-references/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/examples/snippet.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/folders/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/imdb/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/optional/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/reserved-keywords/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions seed/go-sdk/trace/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/go-sdk/unknown/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aab965d

Please sign in to comment.