Skip to content

Commit

Permalink
Improve how we handle Static Helpers (#2716)
Browse files Browse the repository at this point in the history
* load static helpers

* Use binder for polling and paging helpers

* Ignore d.ts files

* Fix imports

* Update poller message

* Cleanup

* Address PR feedback

* Fix path issues

* Fix unit tests

* Fix dirname

* Update helpers

* remove unrelated changes

* Fix test

* Update static helpers

* Re generate tests

* Fix test

* Address PR comments

* Update
  • Loading branch information
joheredi authored Aug 9, 2024
1 parent 7f99fc9 commit 673ee1a
Show file tree
Hide file tree
Showing 253 changed files with 4,527 additions and 7,165 deletions.
92 changes: 0 additions & 92 deletions packages/typespec-test/eng/smoke-test-main.js

This file was deleted.

124 changes: 0 additions & 124 deletions packages/typespec-test/eng/smoke-test-worker.js

This file was deleted.

41 changes: 21 additions & 20 deletions packages/typespec-test/eng/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,7 @@ async function exists(filePath) {
}
}

const calculateMemoryLimit = () => {
const totalMemory = os.totalmem();
const freeMemory = os.freemem();
const minimumFreeMemory = 1024 * 1024 * 1024; // e.g., 1GB

if (freeMemory > minimumFreeMemory) {
// Allow using up to 50% of total memory if there is at least 1GB free
return Math.floor(totalMemory / 1024 / 1024 / 1024 / 2); // in GB
} else {
// Default or lower memory limit if free memory is less than 1GB
return 512; // 512MB as a fallback
}
};

const memoryLimit = calculateMemoryLimit();
console.log(`Memory limit: ${memoryLimit}GB`);
const memoryLimit = 4096; // 4GB

function runCommand(command, args = [], workingDirectory, logger) {
const isLinux = os.platform() === "linux";
Expand Down Expand Up @@ -145,15 +130,31 @@ async function main() {
const root = join(__dirname, "..");

const folders = folder ? [folder] : await readdir(join(root, "test"));
const generatePromises = [];
const maxConcurrentWorkers = 4;
let activePromises = [];

for (const folder of folders) {
const path = join(root, "test", folder);
const generatePromise = generateSmokeTest(path);
generatePromises.push(generatePromise);

const generatePromise = generateSmokeTest(path)
.then((result) => {
activePromises = activePromises.filter((p) => p !== generatePromise);
return result;
})
.catch((error) => {
activePromises = activePromises.filter((p) => p !== generatePromise);
throw error;
});

activePromises.push(generatePromise);

if (activePromises.length >= maxConcurrentWorkers) {
await Promise.race(activePromises);
}
}

await Promise.all(generatePromises);
// Wait for all remaining promises to settle
await Promise.allSettled(activePromises);

if (failed.length > 0) {
console.error("\x1b[31m%s\x1b[0m", `Failed folders: ${failed.join(", ")}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { getLongRunningPoller } from "../pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import {
dataProductPropertiesSerializer,
managedServiceIdentityV4Serializer,
Expand All @@ -17,8 +15,6 @@ import {
ListRoleAssignments,
_DataProductListResult,
} from "../../models/models.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { buildPagedAsyncIterator } from "../pagingHelpers.js";
import { NetworkAnalyticsContext as Client } from "../index.js";
import {
StreamableMethod,
Expand All @@ -27,6 +23,12 @@ import {
createRestError,
} from "@azure-rest/core-client";
import { serializeRecord } from "../../helpers/serializerHelpers.js";
import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../../static-helpers/pagingHelpers.js";
import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import {
DataProductsCreateOptionalParams,
DataProductsGetOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import {
DataProductsCatalog,
_DataProductsCatalogListResult,
} from "../../models/models.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { buildPagedAsyncIterator } from "../pagingHelpers.js";
import { NetworkAnalyticsContext as Client } from "../index.js";
import {
StreamableMethod,
operationOptionsToRequestParameters,
PathUncheckedResponse,
createRestError,
} from "@azure-rest/core-client";
import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../../static-helpers/pagingHelpers.js";
import {
DataProductsCatalogsGetOptionalParams,
DataProductsCatalogsListByResourceGroupOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { getLongRunningPoller } from "../pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import {
dataTypePropertiesSerializer,
dataTypeUpdatePropertiesSerializer,
Expand All @@ -12,15 +10,19 @@ import {
ContainerSasToken,
_DataTypeListResult,
} from "../../models/models.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { buildPagedAsyncIterator } from "../pagingHelpers.js";
import { NetworkAnalyticsContext as Client } from "../index.js";
import {
StreamableMethod,
operationOptionsToRequestParameters,
PathUncheckedResponse,
createRestError,
} from "@azure-rest/core-client";
import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../../static-helpers/pagingHelpers.js";
import { getLongRunningPoller } from "../../static-helpers/pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import {
DataTypesCreateOptionalParams,
DataTypesGetOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// Licensed under the MIT license.

import { Operation, _OperationListResult } from "../../models/models.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { buildPagedAsyncIterator } from "../pagingHelpers.js";
import { NetworkAnalyticsContext as Client } from "../index.js";
import {
StreamableMethod,
operationOptionsToRequestParameters,
PathUncheckedResponse,
createRestError,
} from "@azure-rest/core-client";
import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../../static-helpers/pagingHelpers.js";
import { OperationsListOptionalParams } from "../../models/options.js";

export function _listSend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
listByResourceGroup,
listBySubscription,
} from "../../api/dataProducts/index.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import {
DataProductsCreateOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
listByResourceGroup,
listBySubscription,
} from "../../api/dataProductsCatalogs/index.js";
import { PagedAsyncIterableIterator } from "../../models/pagingTypes.js";
import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js";
import {
DataProductsCatalogsGetOptionalParams,
DataProductsCatalogsListByResourceGroupOptionalParams,
Expand Down
Loading

0 comments on commit 673ee1a

Please sign in to comment.