@@ -39,6 +39,8 @@ const util = __importStar(require("./util"));
3939const TestKind_1 = require ( "./engine/TestKind" ) ;
4040const fs = __importStar ( require ( "fs" ) ) ;
4141const util_1 = require ( "util" ) ;
42+ const FeatureFlagService_1 = require ( "./services/FeatureFlagService" ) ;
43+ const FeatureFlags_1 = require ( "./services/FeatureFlags" ) ;
4244const resultFolder = 'loadTest' ;
4345const reportZipFileName = 'report.zip' ;
4446const resultZipFileName = 'results.zip' ;
@@ -74,8 +76,8 @@ function run() {
7476 }
7577 } ) ;
7678}
77- function getTestAPI ( validate ) {
78- return __awaiter ( this , void 0 , void 0 , function * ( ) {
79+ function getTestAPI ( validate_1 ) {
80+ return __awaiter ( this , arguments , void 0 , function * ( validate , returnTestObj = false ) {
7981 var _a , _b ;
8082 var urlSuffix = "tests/" + testId + "?api-version=" + util . apiConstants . latestVersion ;
8183 urlSuffix = baseURL + urlSuffix ;
@@ -113,6 +115,9 @@ function getTestAPI(validate) {
113115 }
114116 var inputScriptFileInfo = testObj . kind == TestKind_1 . TestKind . URL ? testObj . inputArtifacts . urlTestConfigFileInfo : testObj . inputArtifacts . testScriptFileInfo ;
115117 if ( validate ) {
118+ if ( returnTestObj ) {
119+ return [ inputScriptFileInfo . validationStatus , testObj ] ;
120+ }
116121 return inputScriptFileInfo . validationStatus ;
117122 }
118123 else {
@@ -223,9 +228,10 @@ function uploadTestPlan() {
223228 var startTime = new Date ( ) ;
224229 var maxAllowedTime = new Date ( startTime . getTime ( ) + minutesToAdd * 60000 ) ;
225230 var validationStatus = "VALIDATION_INITIATED" ;
231+ var testObj ;
226232 while ( maxAllowedTime > ( new Date ( ) ) && ( validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED" || validationStatus == null ) ) {
227233 try {
228- validationStatus = yield getTestAPI ( true ) ;
234+ [ validationStatus , testObj ] = yield getTestAPI ( true , true ) ;
229235 }
230236 catch ( e ) {
231237 retry -- ;
@@ -235,8 +241,18 @@ function uploadTestPlan() {
235241 }
236242 yield util . sleep ( 5000 ) ;
237243 }
244+ console . log ( "Validation status of the test plan: " + validationStatus ) ;
238245 if ( validationStatus == null || validationStatus == "VALIDATION_SUCCESS" ) {
239246 console . log ( `Validated test plan for the test successfully.` ) ;
247+ // Get errors from all files
248+ var fileErrors = util . getAllFileErrors ( testObj ) ;
249+ if ( Object . keys ( fileErrors ) . length > 0 ) {
250+ console . log ( "Validation failed for the following files:" ) ;
251+ for ( const [ file , error ] of Object . entries ( fileErrors ) ) {
252+ console . log ( `File: ${ file } , Error: ${ error } ` ) ;
253+ }
254+ throw new Error ( "Validation of one or more files failed. Please correct the errors and try again." ) ;
255+ }
240256 yield createTestRun ( ) ;
241257 }
242258 else if ( validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED" )
@@ -252,7 +268,7 @@ function uploadConfigFile() {
252268 if ( configFiles != undefined && configFiles . length > 0 ) {
253269 for ( let filepath of configFiles ) {
254270 let filename = map . getFileName ( filepath ) ;
255- var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util . apiConstants . latestVersion ;
271+ var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util . apiConstants . latestVersion + ( "&fileType=" + FileType . ADDITIONAL_ARTIFACTS ) ;
256272 urlSuffix = baseURL + urlSuffix ;
257273 let headers = yield map . UploadAndValidateHeader ( ) ;
258274 let uploadresult = yield util . httpClientRetries ( urlSuffix , headers , 'put' , 3 , filepath , true ) ;
@@ -291,6 +307,13 @@ function uploadZipArtifacts() {
291307 let flagValidationPending = true ;
292308 let zipInvalid = false ;
293309 let zipFailureReason = "" ;
310+ // TODO(harshanb): Remove this check once the feature flag is enabled by default.
311+ let isTestScriptFragmentEnabled = yield FeatureFlagService_1 . FeatureFlagService . isFeatureEnabledAsync ( FeatureFlags_1 . FeatureFlags . enableTestScriptFragments , baseURL ) ;
312+ let zipValidationTerminateStates = [ "VALIDATION_SUCCESS" , "VALIDATION_FAILURE" ] ;
313+ if ( isTestScriptFragmentEnabled ) {
314+ // NOT_VALIDATED is a terminal state for the file validation and actual validation will be performed during test script upload
315+ zipValidationTerminateStates . push ( "NOT_VALIDATED" ) ;
316+ }
294317 while ( maxAllowedTime > ( new Date ( ) ) && flagValidationPending ) {
295318 var urlSuffix = "tests/" + testId + "?api-version=" + util . apiConstants . latestVersion ;
296319 urlSuffix = baseURL + urlSuffix ;
@@ -304,7 +327,7 @@ function uploadZipArtifacts() {
304327 flagValidationPending = false ;
305328 if ( testObj && testObj . inputArtifacts && testObj . inputArtifacts . additionalFileInfo ) {
306329 for ( const file of testObj . inputArtifacts . additionalFileInfo ) {
307- if ( file . fileType == FileType . ZIPPED_ARTIFACTS && ( file . validationStatus != "VALIDATION_SUCCESS" && file . validationStatus != "VALIDATION_FAILURE" ) ) {
330+ if ( file . fileType == FileType . ZIPPED_ARTIFACTS && ( file . validationStatus in zipValidationTerminateStates ) ) {
308331 flagValidationPending = true ;
309332 break ;
310333 }
@@ -329,7 +352,12 @@ function uploadZipArtifacts() {
329352 else if ( flagValidationPending ) {
330353 throw new Error ( "Validation of one or more zip artifacts timed out. Please retry." ) ;
331354 }
332- console . log ( `Uploaded and validated ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
355+ if ( isTestScriptFragmentEnabled ) {
356+ console . log ( `Uploaded ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
357+ }
358+ else {
359+ console . log ( `Uploaded and validated ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
360+ }
333361 }
334362 var statuscode = yield uploadPropertyFile ( ) ;
335363 if ( statuscode == 201 ) {
0 commit comments