Skip to content

Commit

Permalink
Load testing RLC GA (Azure#23842)
Browse files Browse the repository at this point in the history
* initial changes stableversion

* old files modified

* Added polling Helper

* Added initial sample and tests

* Added API Review

* Added samples for JS and TS

* pnpm lock file and Readme Update

* Added test and removed locale from readme

* Corrected broken links

* Added dev-tool and eslint

* formatting changes

* Added Browser Recordings

* Code generated from main API

* Added Test Recordings

* Added Samples for JS and TS

* Added Validation Poller

* added champion scenario in single file

* added stop and delete samples

* Update sdk/loadtestservice/load-testing-rest/package.json

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* added TestRun LRO

* modified upload and validte LRO

* Single Test File for test and testrun

* Samples and LRO changes

* Create Test in LRO removed from sample

* Update sdk/loadtestservice/load-testing-rest/src/beginCreateOrUpdateTestRun.ts

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* Update sdk/loadtestservice/load-testing-rest/src/beginUploadTestFile.ts

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* Samples and LRO changes as per review

* Added timeout in samples and test recordings

* New Samples generated and corrected broken link

* Update sdk/loadtestservice/load-testing-rest/samples-dev/stopTest.ts

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* Update sdk/loadtestservice/load-testing-rest/samples-dev/stopTest.ts

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* Update sdk/loadtestservice/load-testing-rest/src/beginUploadTestFile.ts

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>

* Added Sleep Utility

* Updated Readme

* Updated Changelog

* Updated LRO to take queryparams

* Added Tests for LRO impl

* Generated latest Samples

* GetLROHelper Similar impl

* Review Comment Changes

* Updated imports

* LRO error condtions corrected

* Added AbortSignal Changes

* Added LRO Tests

* Removed Begin Methods and added new recordings for tests

* Corrected Broken Links

* rush file update

* build failure due to core-http formatting

* LRO Helper Changes Done

* Ran API extractor again

* Running empty tests

* Review Comments LRO Helper

* New API review

* LRO helper refactoring

* Updated Samples and Readme

* Throw Error when Abort

* Updated Sample

* Updated API View

* Updated package.json, Readme and Samples

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>
  • Loading branch information
mrinal2601 and deyaaeldeen authored Jan 26, 2023
1 parent f266acd commit 9c3cf01
Show file tree
Hide file tree
Showing 112 changed files with 12,114 additions and 5,748 deletions.
5,388 changes: 3,037 additions & 2,351 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sdk/core/core-http/test/credentialTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ describe("Basic Authentication credentials", () => {
it("should fail with options.inHeader and options.inQuery set to null or undefined", function (done) {
(function () {
new ApiKeyCredentials({ inHeader: undefined, inQuery: undefined } as any);
}).should.throw();
}.should.throw());
done();
});

it("should fail without options", function (done) {
(function () {
new (ApiKeyCredentials as any)();
}).should.throw();
}.should.throw());
done();
});

it("should fail with empty options", function (done) {
(function () {
new ApiKeyCredentials({});
}).should.throw();
}.should.throw());
done();
});
});
Expand Down
12 changes: 6 additions & 6 deletions sdk/core/core-http/test/serializationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ describe("msrest", function () {

(function () {
Serializer.serialize(mapper, { length: undefined }, "testobj");
}).should.throw("testobj.length cannot be undefined.");
}.should.throw("testobj.length cannot be undefined."));
});

it("should not allow null when required: true and nullable: false", function () {
Expand All @@ -799,7 +799,7 @@ describe("msrest", function () {

(function () {
Serializer.serialize(mapper, { length: undefined }, "testobj");
}).should.throw("testobj.length cannot be null or undefined.");
}.should.throw("testobj.length cannot be null or undefined."));
});

it("should not allow undefined when required: true and nullable: false", function () {
Expand All @@ -824,7 +824,7 @@ describe("msrest", function () {

(function () {
Serializer.serialize(mapper, { length: undefined }, "testobj");
}).should.throw("testobj.length cannot be null or undefined.");
}.should.throw("testobj.length cannot be null or undefined."));
});

it("should not allow null when required: true and nullable is undefined", function () {
Expand All @@ -837,7 +837,7 @@ describe("msrest", function () {
};
(function () {
Serializer.serialize(mapper, undefined, "testobj");
}).should.throw("testobj cannot be null or undefined.");
}.should.throw("testobj cannot be null or undefined."));
});

it("should not allow undefined when required: true and nullable is undefined", function () {
Expand All @@ -850,7 +850,7 @@ describe("msrest", function () {
};
(function () {
Serializer.serialize(mapper, undefined, "testobj");
}).should.throw("testobj cannot be null or undefined.");
}.should.throw("testobj cannot be null or undefined."));
});

it("should allow null when required: false and nullable: true", function () {
Expand Down Expand Up @@ -879,7 +879,7 @@ describe("msrest", function () {
// tslint:disable-next-line
(function () {
Serializer.serialize(mapper, null, "testobj");
}).should.throw("testobj cannot be null.");
}.should.throw("testobj cannot be null."));
});

it("should allow null when required: false and nullable is undefined", function () {
Expand Down
10 changes: 7 additions & 3 deletions sdk/loadtestservice/load-testing-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

## 1.0.0-beta.2 (Unreleased)

Second preview release of Azure Load Testing client library for Javascript.

### Features Added

### Breaking Changes
- Added `LoadTestClient.beginUploadTestFile` and `LoadTestClient.beginCreateOrUpdateTestRun` Long-Running operation

### Bugs Fixed
### Breaking Changes

### Other Changes
- Added metric namespaces and metric dimensions
- File upload now uses `application/octet-stream` instead of `multipart/form-data`
- File upload now uses file name as primary identifier instead of `fileId`

## 1.0.0-beta.1 (2022-10-19)

Expand Down
148 changes: 121 additions & 27 deletions sdk/loadtestservice/load-testing-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Azure Load Testing provides client library in JavaScript to the user by which th

Various documentation is available to help you get started

<!-- - [Source code][source_code] -->

- [Source code][source_code]
- [API reference documentation][api_reference_doc]
- [Product Documentation][product_documentation]

Expand Down Expand Up @@ -46,6 +45,13 @@ can be used to authenticate the client.
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

```javascript
import AzureLoadTesting, { AzureLoadTestingClient } from "@azure-rest/load-testing";
import { DefaultAzureCredential } from "@azure/identity";

const Client: AzureLoadTestingClient = AzureLoadTesting(Endpoint, new DefaultAzureCredential());
```

## Key concepts

The following components make up the Azure Load Testing Service. The Azure Load Test client library for JavaScript allows you to interact with each of these components through the use of a dedicated client object.
Expand Down Expand Up @@ -93,20 +99,20 @@ In the above example, `eus` represents the Azure region `East US`.
### Creating a load test

```javascript
import AzureLoadTesting, { AzureLoadTestingClient } from "@azure-rest/load-testing";
import { AzureLoadTestingClient } from "@azure-rest/load-testing";
import { DefaultAzureCredential } from "@azure/identity";

var TEST_ID = "some-test-id";
var DISPLAY_NAME = "my-load-test";

const client: AzureLoadTestingClient = AzureLoadTesting(Endpoint, new DefaultAzureCredential());

await client.path("/loadtests/{testId}", TEST_ID).patch({
await client.path("/tests/{testId}", TEST_ID).patch({
contentType: "application/merge-patch+json",
body: {
displayName: DISPLAY_NAME,
description: "",
loadTestConfig: {
loadTestConfiguration: {
engineInstances: 1,
splitAllCSVs: false,
},
Expand All @@ -120,46 +126,134 @@ await client.path("/loadtests/{testId}", TEST_ID).patch({
### Uploading .jmx file to a Test

```javascript
import { AzureLoadTestingClient } from "@azure-rest/load-testing";
import { AzureLoadTestingClient, getLongRunningPoller } from "@azure-rest/load-testing";
import { DefaultAzureCredential } from "@azure/identity";
import { createReadStream } from "fs";

const client: AzureLoadTestingClient = AzureLoadTesting(Endpoint, new DefaultAzureCredential());

var TEST_ID = "some-test-id";
var FILE_ID = "some-file-id";
const readStream = createReadStream("./sample.jmx");

const client: AzureLoadTestingClient = AzureLoadTesting(Endpoint, new DefaultAzureCredential());

await client.path("/loadtests/{testId}/files/{fileId}", TEST_ID, FILE_ID).put({
contentType: "multipart/form-data",
body: {
file: readStream,
},
});
const fileUploadResult = await client
.path("/tests/{testId}/files/{fileName}", TEST_ID, "sample.jmx")
.put({
contentType: "application/octet-stream",
body: readStream,
});

if (isUnexpected(fileUploadResult)) {
throw fileUploadResult.body.error;
}

let fileValidateResult;
const fileValidatePoller = await getLongRunningPoller(client, fileUploadResult);
try{
fileValidateResult = await fileValidatePoller.pollUntilDone({
abortSignal: AbortController.timeout(120*1000), // timeout of 120 seconds
});} catch (ex: any) {
new Error("Error in polling file Validation" + ex.message); //polling timed out
}

if (fileUploadPoller.getOperationState().status != "succeeded" && fileValidateResult)
throw new Error(
"There is some issue in validation, please make sure uploaded file is a valid JMX." +
fileValidateResult.body.validationFailureDetails
);
```

### Running a Test
### Running a Test and fetching Metrics

```javascript
import { AzureLoadTestingClient } from "@azure-rest/load-testing";
import { AzureLoadTestingClient, getLongRunningPoller } from "@azure-rest/load-testing";
import { DefaultAzureCredential } from "@azure/identity";

var TEST_ID = "some-test-id";
var TEST_RUN_ID = "some-testrun-id";
var DISPLAY_NAME = "my-load-test-run";

const client: AzureLoadTestingClient = AzureLoadTesting(Endpoint, new DefaultAzureCredential());

await client.path("/testruns/{testRunId}", TEST_RUN_ID).patch({
var TEST_ID = "some-test-id";
var DISPLAY_NAME = "my-load-test";
var TEST_RUN_ID = "some-test-run-id";

// Creating/Updating the test run
const testRunCreationResult = await client.path("/test-runs/{testRunId}", TEST_RUN_ID).patch({
contentType: "application/merge-patch+json",
body: {
testId: TEST_ID,
displayName: DISPLAY_NAME,
},
});

var result = await client.path("/testruns/{testRunId}", TEST_RUN_ID).get();
console.log(result);
if (isUnexpected(testRunCreationResult)) {
throw testRunCreationResult.body.error;
}

if (testRunCreationResult.body.testRunId === undefined)
throw new Error("Test Run ID returned as undefined.");

const testRunPoller = await getLongRunningPoller(client, testRunCreationResult);
let testRunResult;

try {
testRunResult = await testRunPoller.pollUntilDone({
abortSignal: AbortController.timeout(60000), // timeout of 60 seconds
});
} catch (ex: any) {
new Error("Error in polling test run completion" + ex.message); //polling timed out
}

if (testRunPoller.getOperationState().status != "succeeded")
throw new Error("There is some issue in running the test, Error Response : " + testRunResult);

if (testRunResult) {
let testRunStarttime = testRunResult.body.startDateTime;
let testRunEndTime = testRunResult.body.endDateTime;

// get list of all metric namespaces and pick the first one
const metricNamespaces = await client
.path("/test-runs/{testRunId}/metric-namespaces", testRunId)
.get();

if (isUnexpected(metricNamespaces)) {
throw metricNamespaces.body.error;
}

const metricNamespace = metricNamespaces.body.value[0];

if (metricNamespace.name === undefined) {
throw "No Metric Namespace name is defined.";
}

// get list of all metric definitions and pick the first one
const metricDefinitions = await client
.path("/test-runs/{testRunId}/metric-definitions", testRunId)
.get({
queryParameters: {
metricNamespace: metricNamespace.name,
},
});

if (isUnexpected(metricDefinitions)) {
throw metricDefinitions.body.error;
}

const metricDefinition = metricDefinitions.body.value[0];

if (metricDefinition.name === undefined) {
throw "No Metric Namespace name is defined.";
}

// fetch client metrics using metric namespace and metric name
const metricsResult = await client.path("/test-runs/{testRunId}/metrics", testRunId).post({
queryParameters: {
metricname: metricDefinition.name,
metricNamespace: metricNamespace.name,
timespan: testRunStarttime + "/" + testRunEndTime,
},
});

console.log(metricsResult);
console.log(testRunResult);
}
```

## Troubleshooting
Expand All @@ -180,7 +274,7 @@ For more detailed instructions on how to enable logs, you can look at the [@azur

Azure Loading Testing JavaScript SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered.

<!-- See [Azure Load Testing samples][sample_code]. -->
See [Azure Load Testing samples][sample_code].

## Contributing

Expand All @@ -193,9 +287,9 @@ For details on contributing to this repository, see the [contributing guide](htt
5. Create new Pull Request

<!-- LINKS -->
<!-- [source_code]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/loadtesting/azure-developer-loadtesting/src -->
<!-- [sample_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/loadtestservice/load-testing-rest/samples/v1-beta -->

[source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/loadtestservice/load-testing-rest/src
[sample_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/loadtestservice/load-testing-rest/samples/v1-beta
[api_reference_doc]: https://docs.microsoft.com/rest/api/loadtesting/
[product_documentation]: https://azure.microsoft.com/services/load-testing/
[azure_subscription]: https://azure.microsoft.com/free/
2 changes: 2 additions & 0 deletions sdk/loadtestservice/load-testing-rest/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function (config) {
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["source-map-support", "mocha"],

failOnEmptyTestSuite: false,

plugins: [
"karma-mocha",
"karma-mocha-reporter",
Expand Down
Loading

0 comments on commit 9c3cf01

Please sign in to comment.