@@ -33,7 +33,7 @@ func TestMain(m *testing.M) {
3333}
3434
3535func TestRequestMetric (t * testing.T ) {
36- metric := NewRequestMetric ()
36+ metric := NewRequestMetric ("us-east-1" )
3737 agg := metric .aggregatedResults
3838 if agg .TotalReqs != 0 {
3939 t .Error ("totalRequestsFinished should be initialized with 0" )
@@ -67,7 +67,7 @@ func TestRequestMetric(t *testing.T) {
6767func TestAddRequestStatus (t * testing.T ) {
6868 success := 200
6969 successStr := strconv .Itoa (success )
70- metric := NewRequestMetric ()
70+ metric := NewRequestMetric ("us-east-1" )
7171 result := & requestResult {
7272 Status : success ,
7373 }
@@ -86,7 +86,7 @@ func TestAddRequest(t *testing.T) {
8686 elapsedFirst := int64 (100 )
8787 elapsedLast := int64 (300 )
8888
89- metric := NewRequestMetric ()
89+ metric := NewRequestMetric ("us-east-1" )
9090 result := & requestResult {
9191 Time : 400 ,
9292 ElapsedFirstByte : elapsedFirst ,
@@ -193,7 +193,7 @@ func TestAddRequest(t *testing.T) {
193193}
194194
195195func TestResetAndKeepTotalReqs (t * testing.T ) {
196- metric := NewRequestMetric ()
196+ metric := NewRequestMetric ("us-east-1" )
197197 agg := metric .aggregatedResults
198198 agg .TotalReqs = 7
199199 metric .firstRequestTime = 123
@@ -242,7 +242,7 @@ func TestMetricsAggregate(t *testing.T) {
242242 elapsedFirst := int64 (100 )
243243 elapsedLast := int64 (300 )
244244
245- metric := NewRequestMetric ()
245+ metric := NewRequestMetric ("us-east-1" )
246246 result := & requestResult {
247247 Time : 10000000 ,
248248 Elapsed : 10000000 ,
@@ -337,12 +337,11 @@ func TestQuitOnLambdaTimeout(t *testing.T) {
337337
338338 reportingFrequency := time .Duration (5 ) * time .Second
339339 settings := LambdaSettings {
340- MaxRequestCount : 3 ,
341- ConcurrencyCount : 1 ,
342- ReportingFrequency : reportingFrequency ,
343- StresstestTimeout : 10 ,
344- LambdaExecTimeoutSeconds : 1 ,
345- LambdaRegion : "us-east-1" ,
340+ MaxRequestCount : 3 ,
341+ ConcurrencyCount : 1 ,
342+ ReportingFrequency : reportingFrequency ,
343+ StresstestTimeout : 10 ,
344+ LambdaRegion : "us-east-1" ,
346345 }
347346 settings .RequestParameters .URL = urlStr
348347 sender := & TestResultSender {}
@@ -353,6 +352,7 @@ func TestQuitOnLambdaTimeout(t *testing.T) {
353352 function := & lambdaTestFunction {
354353 lambda : lambda ,
355354 }
355+ lambda .Settings .LambdaExecTimeoutSeconds = 1
356356 RunOrFailAfterTimout (t , function , 1400 )
357357 resLength := len (sender .sentResults )
358358 timeoutRemaining := lambda .Settings .StresstestTimeout
@@ -389,7 +389,7 @@ func TestMetricSendResults(t *testing.T) {
389389 ConnectionError : false ,
390390 }
391391
392- metric := NewRequestMetric ()
392+ metric := NewRequestMetric ("us-east-1" )
393393 sender := & TestResultSender {}
394394
395395 metric .addRequest (result )
@@ -404,24 +404,35 @@ func TestRunLoadTestWithHighConcurrency(t *testing.T) {
404404 server := createAndStartTestServer ()
405405 defer server .Stop ()
406406
407- runLoadTestWith (t , 500 , 100 , 500 )
407+ runLoadTestWithDefaultExecTimeout (t , 500 , 100 , 500 )
408408}
409409
410410func TestRunLoadTestWithOneRequest (t * testing.T ) {
411411 server := createAndStartTestServer ()
412412 defer server .Stop ()
413413
414- runLoadTestWith (t , 1 , - 1 , 50 )
414+ runLoadTestWithDefaultExecTimeout (t , 1 , - 1 , 50 )
415415}
416416
417417func TestRunLoadTestWithZeroRequests (t * testing.T ) {
418418 server := createAndStartTestServer ()
419419 defer server .Stop ()
420420
421- runLoadTestWith (t , 0 , 1 , 50 )
421+ runLoadTestWithDefaultExecTimeout (t , 1 , 1 , 120 )
422+ }
423+
424+ func TestRunWithExecTimeout (t * testing.T ) {
425+ server := createAndStartTestServer ()
426+ defer server .Stop ()
427+
428+ runLoadTestWith (t , 0 , 1 , 1 , 1050 )
429+ }
430+
431+ func runLoadTestWithDefaultExecTimeout (t * testing.T , requestCount int , concurrency int , milliseconds int ) {
432+ runLoadTestWith (t , requestCount , 0 , concurrency , milliseconds )
422433}
423434
424- func runLoadTestWith (t * testing.T , requestCount int , concurrency int , milliseconds int ) {
435+ func runLoadTestWith (t * testing.T , requestCount int , stresstestTimeout int , concurrency int , milliseconds int ) {
425436 if testing .Short () {
426437 t .Skip ("skipping test in short mode." )
427438 }
@@ -430,6 +441,7 @@ func runLoadTestWith(t *testing.T, requestCount int, concurrency int, millisecon
430441 MaxRequestCount : requestCount ,
431442 ConcurrencyCount : concurrency ,
432443 ReportingFrequency : reportingFrequency ,
444+ StresstestTimeout : stresstestTimeout ,
433445 }
434446 settings .RequestParameters .URL = urlStr
435447 sender := & TestResultSender {}
@@ -447,7 +459,7 @@ func runLoadTestWith(t *testing.T, requestCount int, concurrency int, millisecon
447459 if results .Finished != true {
448460 t .Error ("the lambda should have finished it's results" )
449461 }
450- if results .TotalReqs != requestCount {
462+ if results .TotalReqs != requestCount && requestCount > 0 {
451463 t .Errorf ("the lambda generated results for %d request, expected %d" , results .TotalReqs , requestCount )
452464 }
453465}
0 commit comments