Skip to content

Commit dc2ae74

Browse files
authored
changes for EINVAL issue reported by customer, latest version changes (#96)
* changes for EINVAL issue reported by customer, latest version changes * adding ubuntu and windows in agents * changes to put the windows and ubuntu parellely * minor changes * console log ahcnage * some changes for guids. * some check * try * try * change * some change * change for the validation of testName * no need of runner anyway * file renames and deleting un-necessary files * pr comment * adding a comment * change comment * check for the results and reports * check for directory too. * try * negative test to check a stage * revert negative testing * pr comments * nit change in commments * removing un-used func * validation file changes.
1 parent bf30be5 commit dc2ae74

File tree

9 files changed

+255
-180
lines changed

9 files changed

+255
-180
lines changed

.github/workflows/pr_check_load_test.yml

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: pr build check
1+
name: pr build check for some E2E tests
22

33
on:
44
push:
@@ -13,18 +13,21 @@ on:
1313
- main
1414

1515
env:
16-
LOAD_TEST_RESOURCE: "rbac-test"
17-
LOAD_TEST_RESOURCE_GROUP: "radhika-test"
18-
COMMIT_ID : ${{ github.sha }}
16+
LOAD_TEST_RESOURCE: ${{ secrets.LOAD_TEST_RESOURCE_NAME }}
17+
LOAD_TEST_RESOURCE_GROUP: ${{ secrets.LOAD_TEST_RESOURCE_GROUP_NAME }}
18+
19+
permissions:
20+
id-token: write # This is required for requesting the JWT
21+
contents : read # This is required for actions/checkout
1922

2023
jobs:
2124
run-integration-test:
2225
environment: automation test
2326
name: Validate PR
2427
strategy:
2528
matrix:
26-
os: [windows-latest]
27-
configFile: ['sample-test-url.yaml', 'sample-test-jmx.yaml']
29+
os: [ubuntu-latest, windows-latest]
30+
configFile: ['sample-test-url.yaml', 'sample-test-jmx.yaml']
2831

2932
runs-on: ${{ matrix.os }}
3033
steps:
@@ -43,13 +46,49 @@ jobs:
4346
4447
- name: Azure authentication
4548
uses: azure/login@v1
49+
continue-on-error: false
4650
with:
47-
creds: ${{ secrets.AZURE_CREDENTIALS }}
48-
51+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
52+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
53+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
54+
55+
- name: Generate GUID
56+
id: guid
57+
run: |
58+
if [[ "${{ runner.os }}" == "Windows" ]]; then
59+
echo "::set-output name=GUID::$(powershell -Command "[guid]::NewGuid().ToString()")"
60+
else
61+
echo "::set-output name=GUID::$(uuidgen)"
62+
fi
63+
shell : bash
64+
65+
- name: Set up testName
66+
shell: bash
67+
run: |
68+
# copying the files to a new file and editing the testId for each file in the copied file.
69+
# replacing 'testId'(the thing present in the file.) with the new testId ('${{ steps.guid.outputs.GUID }}') in the copied file.
70+
cp ${{ matrix.configFile }} test-config-${{ steps.guid.outputs.GUID }}.yaml
71+
sed -i 's/testId/${{ steps.guid.outputs.GUID }}/g' test-config-${{ steps.guid.outputs.GUID }}.yaml
72+
4973
- name: 'Azure Load Testing'
5074
uses: ./
5175
with:
52-
loadTestConfigFile: ${{ matrix.configFile }}
76+
loadTestConfigFile: test-config-${{ steps.guid.outputs.GUID }}.yaml
5377
loadTestResource: ${{ env.LOAD_TEST_RESOURCE }}
5478
resourceGroup: ${{ env.LOAD_TEST_RESOURCE_GROUP }}
55-
79+
continue-on-error: true
80+
81+
- name: Check for results and report files
82+
run: |
83+
if [[ -d "./loadTest" ]]; then
84+
if [[ -f "./loadTest/results.zip" && -f "./loadTest/report.zip" ]]; then
85+
echo "Both results.zip and report.zip files are present."
86+
else
87+
echo "One or both of the files are missing."
88+
exit 1
89+
fi
90+
else
91+
echo "loadTest directory is missing."
92+
exit 1
93+
fi
94+
shell: bash

lib/main.js

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
3434
Object.defineProperty(exports, "__esModule", { value: true });
3535
exports.getExistingEnv = exports.getExistingParams = exports.getExistingCriteria = void 0;
3636
const core = __importStar(require("@actions/core"));
37-
const httpc = require("typed-rest-client/HttpClient");
3837
const map = __importStar(require("./mappers"));
3938
const util = __importStar(require("./util"));
4039
const fs = __importStar(require("fs"));
4140
const util_1 = require("util");
4241
const util_2 = require("./util");
4342
const resultFolder = 'loadTest';
43+
const reportZipFileName = 'report.zip';
44+
const resultZipFileName = 'results.zip';
4445
let baseURL = '';
45-
const httpClient = new httpc.HttpClient('MALT-GHACTION');
4646
let testId = '';
4747
let existingCriteria = {};
4848
let existingParams = {};
@@ -74,8 +74,9 @@ function run() {
7474
});
7575
}
7676
function getTestAPI(validate) {
77+
var _a, _b;
7778
return __awaiter(this, void 0, void 0, function* () {
78-
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
79+
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.latestVersion;
7980
urlSuffix = baseURL + urlSuffix;
8081
let header = yield map.getTestHeader();
8182
let testResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
@@ -85,10 +86,21 @@ function getTestAPI(validate) {
8586
+ "https://docs.microsoft.com/azure/load-testing/tutorial-cicd-github-actions#configure-the-github-actions-workflow-to-run-a-load-test ";
8687
throw new Error(message);
8788
}
88-
if (testResult.message.statusCode != 200 && testResult.message.statusCode != 201 && testResult.message.statusCode != 404) {
89-
let testObj = yield util.getResultObj(testResult);
90-
console.log(testObj ? testObj : util.ErrorCorrection(testResult));
91-
throw new Error("Error in getting the test.");
89+
if (testResult.message.statusCode != 200 && testResult.message.statusCode != 201) {
90+
if (validate) { // validate is called, then get should not be false, and this validate had retries because of the conflicts in jmx test, so lets not print in the console, instead put this in the error itself.
91+
let testObj = yield util.getResultObj(testResult);
92+
let err = ((_a = testObj === null || testObj === void 0 ? void 0 : testObj.error) === null || _a === void 0 ? void 0 : _a.message) ? (_b = testObj === null || testObj === void 0 ? void 0 : testObj.error) === null || _b === void 0 ? void 0 : _b.message : util.ErrorCorrection(testResult);
93+
throw new Error(err);
94+
}
95+
else if (!validate && testResult.message.statusCode != 404) { // if not validate, then its to check if it is edit or create thats all, so it should not throw the error for 404.
96+
let testObj = yield util.getResultObj(testResult);
97+
console.log(testObj ? testObj : util.ErrorCorrection(testResult));
98+
throw new Error("Error in getting the test.");
99+
}
100+
// note : kumarmoh
101+
/// else {
102+
// do nothing if the validate = false and status code is 404, as it is for create test.
103+
// } this is just for comment
92104
}
93105
if (testResult.message.statusCode == 200) {
94106
let testObj = yield util.getResultObj(testResult);
@@ -115,7 +127,7 @@ function getTestAPI(validate) {
115127
}
116128
function deleteFileAPI(filename) {
117129
return __awaiter(this, void 0, void 0, function* () {
118-
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
130+
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.latestVersion;
119131
urlSuffix = baseURL + urlSuffix;
120132
let header = yield map.getTestHeader();
121133
let delFileResult = yield util.httpClientRetries(urlSuffix, header, 'del', 3, "");
@@ -128,7 +140,7 @@ function deleteFileAPI(filename) {
128140
}
129141
function createTestAPI() {
130142
return __awaiter(this, void 0, void 0, function* () {
131-
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
143+
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.latestVersion;
132144
urlSuffix = baseURL + urlSuffix;
133145
var createData = map.createTestData();
134146
let header = yield map.createTestHeader();
@@ -191,7 +203,7 @@ function uploadTestPlan() {
191203
let retry = 5;
192204
let filepath = map.getTestFile();
193205
let filename = map.getFileName(filepath);
194-
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
206+
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.latestVersion;
195207
if (map.getTestKind() == util_2.TestKind.URL) {
196208
urlSuffix = urlSuffix + ("&fileType=" + FileType.URL_TEST_CONFIG);
197209
}
@@ -209,14 +221,14 @@ function uploadTestPlan() {
209221
var startTime = new Date();
210222
var maxAllowedTime = new Date(startTime.getTime() + minutesToAdd * 60000);
211223
var validationStatus = "VALIDATION_INITIATED";
212-
while (maxAllowedTime > (new Date()) && (validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED")) {
224+
while (maxAllowedTime > (new Date()) && (validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED" || validationStatus == null)) {
213225
try {
214226
validationStatus = yield getTestAPI(true);
215227
}
216228
catch (e) {
217229
retry--;
218230
if (retry == 0) {
219-
throw new Error("Unable to validate the test plan. Please retry.");
231+
throw new Error("Unable to validate the test plan. Please retry. Failed with error :" + e);
220232
}
221233
}
222234
yield util.sleep(5000);
@@ -238,7 +250,7 @@ function uploadConfigFile() {
238250
if (configFiles != undefined && configFiles.length > 0) {
239251
for (let filepath of configFiles) {
240252
let filename = map.getFileName(filepath);
241-
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion;
253+
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.latestVersion;
242254
urlSuffix = baseURL + urlSuffix;
243255
let headers = yield map.UploadAndValidateHeader();
244256
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, filepath, true);
@@ -254,14 +266,14 @@ function uploadConfigFile() {
254266
});
255267
}
256268
function uploadZipArtifacts() {
269+
var _a;
257270
return __awaiter(this, void 0, void 0, function* () {
258-
var _a;
259271
let zipFiles = map.getZipFiles();
260272
if (zipFiles != undefined && zipFiles.length > 0) {
261273
console.log("Uploading and validating the zip artifacts");
262274
for (let filepath of zipFiles) {
263275
let filename = map.getFileName(filepath);
264-
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion + "&fileType=" + FileType.ZIPPED_ARTIFACTS;
276+
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.latestVersion + "&fileType=" + FileType.ZIPPED_ARTIFACTS;
265277
urlSuffix = baseURL + urlSuffix;
266278
let headers = yield map.UploadAndValidateHeader();
267279
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, filepath, true);
@@ -278,11 +290,15 @@ function uploadZipArtifacts() {
278290
let zipInvalid = false;
279291
let zipFailureReason = "";
280292
while (maxAllowedTime > (new Date()) && flagValidationPending) {
281-
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
293+
var urlSuffix = "tests/" + testId + "?api-version=" + util.apiConstants.latestVersion;
282294
urlSuffix = baseURL + urlSuffix;
283295
let header = yield map.getTestHeader();
284296
let testResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
285297
let testObj = yield util.getResultObj(testResult);
298+
if (testResult.message.statusCode != 200 && testResult.message.statusCode != 201) {
299+
console.log(testObj ? testObj : util.ErrorCorrection(testResult));
300+
throw new Error("Error in getting the test.");
301+
}
286302
flagValidationPending = false;
287303
if (testObj && testObj.inputArtifacts && testObj.inputArtifacts.additionalFileInfo) {
288304
for (const file of testObj.inputArtifacts.additionalFileInfo) {
@@ -324,7 +340,7 @@ function uploadPropertyFile() {
324340
let propertyFile = map.getPropertyFile();
325341
if (propertyFile != undefined) {
326342
let filename = map.getFileName(propertyFile);
327-
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.tm20240301previewVersion + "&fileType=" + FileType.USER_PROPERTIES;
343+
var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util.apiConstants.latestVersion + "&fileType=" + FileType.USER_PROPERTIES;
328344
urlSuffix = baseURL + urlSuffix;
329345
let headers = yield map.UploadAndValidateHeader();
330346
let uploadresult = yield util.httpClientRetries(urlSuffix, headers, 'put', 3, propertyFile);
@@ -342,7 +358,7 @@ function createTestRun() {
342358
return __awaiter(this, void 0, void 0, function* () {
343359
const tenantId = map.getTenantId();
344360
const testRunId = util.getUniqueId();
345-
var urlSuffix = "test-runs/" + testRunId + "?tenantId=" + tenantId + "&api-version=" + util.apiConstants.tm20240301previewVersion;
361+
var urlSuffix = "test-runs/" + testRunId + "?tenantId=" + tenantId + "&api-version=" + util.apiConstants.latestVersion;
346362
urlSuffix = baseURL + urlSuffix;
347363
const ltres = core.getInput('loadTestResource');
348364
const runDisplayName = core.getInput('loadTestRunName');
@@ -378,21 +394,24 @@ function createTestRun() {
378394
}
379395
function getTestRunAPI(testRunId, testStatus, startTime) {
380396
return __awaiter(this, void 0, void 0, function* () {
381-
var urlSuffix = "test-runs/" + testRunId + "?api-version=" + util.apiConstants.tm20240301previewVersion;
397+
var urlSuffix = "test-runs/" + testRunId + "?api-version=" + util.apiConstants.latestVersion;
382398
urlSuffix = baseURL + urlSuffix;
383399
while (!util.isTerminalTestStatus(testStatus)) {
384400
let header = yield map.getTestRunHeader();
385401
let testRunResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
386402
let testRunObj = yield util.getResultObj(testRunResult);
387-
if (testRunObj == null) {
388-
throw new Error(util.ErrorCorrection(testRunResult));
403+
if (testRunResult.message.statusCode != 200 && testRunResult.message.statusCode != 201) {
404+
console.log(testRunObj ? testRunObj : util.ErrorCorrection(testRunResult));
405+
throw new Error("Error in getting the test run");
389406
}
390407
testStatus = testRunObj.status;
391408
if (util.isTerminalTestStatus(testStatus)) {
392409
let vusers = null;
393410
let count = 0;
411+
let reportsAvailable = false;
412+
console.log("Test run completed. Polling for statistics and dashboard report to populate.");
394413
// Polling for max 3 min for statistics and pass fail criteria to populate
395-
while ((0, util_1.isNullOrUndefined)(vusers) && count < 18) {
414+
while ((!reportsAvailable || (0, util_1.isNullOrUndefined)(vusers)) && count < 18) {
396415
yield util.sleep(10000);
397416
let header = yield map.getTestRunHeader();
398417
let testRunResult = yield util.httpClientRetries(urlSuffix, header, 'get', 3, "");
@@ -401,12 +420,15 @@ function getTestRunAPI(testRunId, testStatus, startTime) {
401420
throw new Error(util.ErrorCorrection(testRunResult));
402421
}
403422
if (testRunResult.message.statusCode != 200 && testRunResult.message.statusCode != 201) {
404-
let testRunObj = yield util.getResultObj(testRunResult);
405423
console.log(testRunObj ? testRunObj : util.ErrorCorrection(testRunResult));
406-
throw new Error("Error in getting the test-run");
424+
throw new Error("Error in getting the test run");
407425
}
408426
vusers = testRunObj.virtualUsers;
409427
count++;
428+
let testReport = util.getReportFolder(testRunObj.testArtifacts);
429+
if (testReport) {
430+
reportsAvailable = true;
431+
}
410432
}
411433
if (testRunObj && testRunObj.startDateTime) {
412434
startTime = new Date(testRunObj.startDateTime);
@@ -420,16 +442,28 @@ function getTestRunAPI(testRunId, testStatus, startTime) {
420442
util.printCriteria(testRunObj.passFailCriteria.passFailMetrics);
421443
if (testRunObj.testRunStatistics != null)
422444
util.printClientMetrics(testRunObj.testRunStatistics);
423-
var testResultUrl = util.getResultFolder(testRunObj.testArtifacts);
445+
let testResultUrl = util.getResultFolder(testRunObj.testArtifacts);
424446
if (testResultUrl != null) {
425-
const response = yield util.httpClientRetries(testResultUrl, { 'content-type': 'application/merge-patch+json' }, 'get', 3, "");
447+
const response = yield util.httpClientRetries(testResultUrl, {}, 'get', 3, "");
426448
if (response.message.statusCode != 200) {
427449
let respObj = yield util.getResultObj(response);
428450
console.log(respObj ? respObj : util.ErrorCorrection(response));
429451
throw new Error("Error in fetching results ");
430452
}
431453
else {
432-
yield util.getResultsFile(response);
454+
yield util.uploadFileToResultsFolder(response, resultZipFileName);
455+
}
456+
}
457+
let testReportUrl = util.getReportFolder(testRunObj.testArtifacts);
458+
if (testReportUrl != null) {
459+
const response = yield util.httpClientRetries(testReportUrl, {}, 'get', 3, "");
460+
if (response.message.statusCode != 200) {
461+
let respObj = yield util.getResultObj(response);
462+
console.log(respObj ? respObj : util.ErrorCorrection(response));
463+
throw new Error("Error in fetching report ");
464+
}
465+
else {
466+
yield util.uploadFileToResultsFolder(response, reportZipFileName);
433467
}
434468
}
435469
if (testRunObj.status === "FAILED" || testRunObj.status === "CANCELLED") {

0 commit comments

Comments
 (0)