@@ -6,6 +6,8 @@ import * as Util from './engine/Util';
66import { TestKind } from "./engine/TestKind" ;
77import * as fs from 'fs' ;
88import { isNullOrUndefined } from 'util' ;
9+ import { FeatureFlagService } from './services/FeatureFlagService' ;
10+ import { FeatureFlags } from './services/FeatureFlags' ;
911
1012const resultFolder = 'loadTest' ;
1113const reportZipFileName = 'report.zip' ;
@@ -39,7 +41,7 @@ async function run() {
3941 core . setFailed ( err . message ) ;
4042 }
4143}
42- async function getTestAPI ( validate :boolean ) {
44+ async function getTestAPI ( validate :boolean , returnTestObj : boolean = false ) {
4345 var urlSuffix = "tests/" + testId + "?api-version=" + util . apiConstants . latestVersion ;
4446 urlSuffix = baseURL + urlSuffix ;
4547 let header = await map . getTestHeader ( ) ;
@@ -74,7 +76,11 @@ async function getTestAPI(validate:boolean) {
7476 testObj . kind = testObj . testType ;
7577 }
7678 var inputScriptFileInfo = testObj . kind == TestKind . URL ? testObj . inputArtifacts . urlTestConfigFileInfo :testObj . inputArtifacts . testScriptFileInfo ;
79+
7780 if ( validate ) {
81+ if ( returnTestObj ) {
82+ return [ inputScriptFileInfo . validationStatus , testObj ] ;
83+ }
7884 return inputScriptFileInfo . validationStatus ;
7985 }
8086 else
@@ -185,9 +191,10 @@ async function uploadTestPlan()
185191 var startTime = new Date ( ) ;
186192 var maxAllowedTime = new Date ( startTime . getTime ( ) + minutesToAdd * 60000 ) ;
187193 var validationStatus = "VALIDATION_INITIATED" ;
194+ var testObj ;
188195 while ( maxAllowedTime > ( new Date ( ) ) && ( validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED" || validationStatus == null ) ) {
189196 try {
190- validationStatus = await getTestAPI ( true ) ;
197+ [ validationStatus , testObj ] = await getTestAPI ( true , true ) ;
191198 }
192199 catch ( e :any ) {
193200 retry -- ;
@@ -197,8 +204,21 @@ async function uploadTestPlan()
197204 }
198205 await util . sleep ( 5000 ) ;
199206 }
207+ console . log ( "Validation status of the test plan: " + validationStatus ) ;
200208 if ( validationStatus == null || validationStatus == "VALIDATION_SUCCESS" ) {
201209 console . log ( `Validated test plan for the test successfully.` ) ;
210+
211+ // Get errors from all files
212+ var fileErrors = util . getAllFileErrors ( testObj ) ;
213+
214+ if ( Object . keys ( fileErrors ) . length > 0 ) {
215+ console . log ( "Validation failed for the following files:" ) ;
216+ for ( const [ file , error ] of Object . entries ( fileErrors ) ) {
217+ console . log ( `File: ${ file } , Error: ${ error } ` ) ;
218+ }
219+ throw new Error ( "Validation of one or more files failed. Please correct the errors and try again." ) ;
220+ }
221+
202222 await createTestRun ( ) ;
203223 }
204224 else if ( validationStatus == "VALIDATION_INITIATED" || validationStatus == "NOT_VALIDATED" )
@@ -213,7 +233,7 @@ async function uploadConfigFile()
213233 if ( configFiles != undefined && configFiles . length > 0 ) {
214234 for ( let filepath of configFiles ) {
215235 let filename = map . getFileName ( filepath ) ;
216- var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util . apiConstants . latestVersion ;
236+ var urlSuffix = "tests/" + testId + "/files/" + filename + "?api-version=" + util . apiConstants . latestVersion + ( "&fileType=" + FileType . ADDITIONAL_ARTIFACTS ) ;
217237 urlSuffix = baseURL + urlSuffix ;
218238 let headers = await map . UploadAndValidateHeader ( ) ;
219239 let uploadresult = await util . httpClientRetries ( urlSuffix , headers , 'put' , 3 , filepath , true ) ;
@@ -250,6 +270,15 @@ async function uploadZipArtifacts()
250270 let flagValidationPending = true ;
251271 let zipInvalid = false ;
252272 let zipFailureReason = "" ;
273+
274+ // TODO(harshanb): Remove this check once the feature flag is enabled by default.
275+ let isTestScriptFragmentEnabled = await FeatureFlagService . isFeatureEnabledAsync ( FeatureFlags . enableTestScriptFragments , baseURL ) ;
276+ let zipValidationTerminateStates = [ "VALIDATION_SUCCESS" , "VALIDATION_FAILURE" ] ;
277+ if ( isTestScriptFragmentEnabled ) {
278+ // NOT_VALIDATED is a terminal state for the file validation and actual validation will be performed during test script upload
279+ zipValidationTerminateStates . push ( "NOT_VALIDATED" ) ;
280+ }
281+
253282 while ( maxAllowedTime > ( new Date ( ) ) && flagValidationPending ) {
254283 var urlSuffix = "tests/" + testId + "?api-version=" + util . apiConstants . latestVersion ;
255284 urlSuffix = baseURL + urlSuffix ;
@@ -263,7 +292,7 @@ async function uploadZipArtifacts()
263292 flagValidationPending = false ;
264293 if ( testObj && testObj . inputArtifacts && testObj . inputArtifacts . additionalFileInfo ) {
265294 for ( const file of testObj . inputArtifacts . additionalFileInfo ) {
266- if ( file . fileType == FileType . ZIPPED_ARTIFACTS && ( file . validationStatus != "VALIDATION_SUCCESS" && file . validationStatus != "VALIDATION_FAILURE" ) ) {
295+ if ( file . fileType == FileType . ZIPPED_ARTIFACTS && ( file . validationStatus ! in zipValidationTerminateStates ) ) {
267296 flagValidationPending = true ;
268297 break ;
269298 } else if ( file . fileType == FileType . ZIPPED_ARTIFACTS && file . validationStatus == "VALIDATION_FAILURE" ) {
@@ -285,7 +314,12 @@ async function uploadZipArtifacts()
285314 } else if ( flagValidationPending ) {
286315 throw new Error ( "Validation of one or more zip artifacts timed out. Please retry." ) ;
287316 }
288- console . log ( `Uploaded and validated ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
317+ if ( isTestScriptFragmentEnabled ) {
318+ console . log ( `Uploaded ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
319+ }
320+ else {
321+ console . log ( `Uploaded and validated ${ zipFiles . length } zip artifact(s) for the test successfully.` ) ;
322+ }
289323 }
290324 var statuscode = await uploadPropertyFile ( ) ;
291325 if ( statuscode == 201 ) {
0 commit comments