From 39ee95dbb7f09cef684b2b5c92a5f2d4864198cb Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Thu, 15 Aug 2019 16:39:59 +1200 Subject: [PATCH] fixed test --- handler/batch_test.sh | 4 ++-- handler/batch_test_parallel.sh | 4 ++-- handler/common.go | 25 ++++++++++++++++---- handler/handler_test.go | 42 +++++++++++++++++++--------------- handler/main.go | 31 +++++++++++++------------ handler/task.go | 5 ---- 6 files changed, 64 insertions(+), 47 deletions(-) diff --git a/handler/batch_test.sh b/handler/batch_test.sh index 3ab11cc..532990d 100755 --- a/handler/batch_test.sh +++ b/handler/batch_test.sh @@ -1,7 +1,7 @@ -URL=${1:-https://415mdw939a.execute-api.ap-southeast-2.amazonaws.com/prod/v1/enqueue} +URL=${1:-https://415mdw939a.execute-api.ap-southeast-2.amazonaws.com/dev/v1/call} for id in 484378182 477579437 208013283 987654321 8524255 350622514 4306445 ; do - curl -v -H "Content-Type: application/json" -d "{\"subject\":${id}}" $URL + curl -v -H "Content-Type: application/json" -d "{\"subject\":\"${id}\"}" $URL done diff --git a/handler/batch_test_parallel.sh b/handler/batch_test_parallel.sh index 6b89f46..0f48a2f 100755 --- a/handler/batch_test_parallel.sh +++ b/handler/batch_test_parallel.sh @@ -1,6 +1,6 @@ -export URL=${1:-https://415mdw939a.execute-api.ap-southeast-2.amazonaws.com/prod/v1/enqueue} +export URL=${1:-https://415mdw939a.execute-api.ap-southeast-2.amazonaws.com/dev/v1/call} -xargs -P 100 -L 1 -i -t curl -v -H "Content-Type: application/json" -d "{\"subject\":{}}" $URL < 0, "The number of records should be > 0.") @@ -503,8 +509,8 @@ func testProcessMixed(t *testing.T) { taskRecordCount = 0 _, err = (&Event{ Records: []events.SQSMessage{ - {Body: `{"subject":484378182}`}, - {Body: `{"subject":477579437}`}, + {Body: `{"subject":"484378182"}`}, + {Body: `{"subject":"477579437"}`}, {Body: `{ "orcid": "0000-0001-8228-7153", "url": "https://sandbox.orcid.org/0000-0001-8228-7153", @@ -512,9 +518,9 @@ func testProcessMixed(t *testing.T) { "email": "rad42@mailinator.com", "eppn": "rcir178@auckland.ac.nz" }`}, - {Body: `{"subject":208013283}`}, - {Body: `{"subject":66666666}`}, - {Body: `{"subject":77777777}`}, + {Body: `{"subject":"208013283"}`}, + {Body: `{"subject":"66666666"}`}, + {Body: `{"subject":"77777777"}`}, {Body: `{ "orcid": "0000-0001-6666-7153", "url": "https://sandbox.orcid.org/0000-0001-6666-7153", @@ -531,8 +537,8 @@ func testProcessMixed(t *testing.T) { "email": "dthn7777mailinator.com", "eppn": "dthn7777auckland.ac.nz" }`}, - {Body: `{"subject":987654321}`}, - {Body: `{"subject":8524255}`}, + {Body: `{"subject":"987654321"}`}, + {Body: `{"subject":"8524255"}`}, {Body: `{ "orcid": "0000-0001-8228-7153", "url": "https://sandbox.orcid.org/0000-0001-8228-7153", @@ -541,8 +547,8 @@ func testProcessMixed(t *testing.T) { "email": "rad42@mailinator.com", "eppn": "rcir178@auckland.ac.nz" }`}, - {Body: `{"subject":350622514}`}, - {Body: `{"subject":4306445}`}, + {Body: `{"subject":"350622514"}`}, + {Body: `{"subject":"4306445"}`}, }, }).handle() assert.True(t, taskRecordCount == 3, "The number of records should be 3, got: %d.", taskRecordCount) @@ -552,8 +558,8 @@ func testProcessMixed(t *testing.T) { assert.NotNil(t, err) _, err = (&Event{ Records: []events.SQSMessage{ - {Body: `{"subject":484378182}`}, - {Body: `{"subject":477579437}`}, + {Body: `{"subject":"484378182"}`}, + {Body: `{"subject":"477579437"}`}, }, }).handle() assert.NotNil(t, err) diff --git a/handler/main.go b/handler/main.go index bfa939f..b8fa678 100644 --- a/handler/main.go +++ b/handler/main.go @@ -16,15 +16,15 @@ import ( var lambdazapper *lambdazap.LambdaLogContext -// Response - lambda response -type Response struct { - Message string `json:"message,omitempty"` - Retry bool `json:"retry"` -} +// // Response - lambda response +// type Response struct { +// Message string `json:"message,omitempty"` +// Retry bool `json:"retry"` +// } // HandleRequest handle "AWS lambda" request with a single event message or // a batch of event messages. -func HandleRequest(ctx context.Context, e Event) (Response, error) { +func HandleRequest(ctx context.Context, e Event) (message string, err error) { defer func() { logger.Sync() @@ -32,15 +32,16 @@ func HandleRequest(ctx context.Context, e Event) (Response, error) { logger.Sync() }() - message, err := e.handle() - if err != nil { - if message != "" { - message += ": " + err.Error() - } else { - message = err.Error() - } - } - return Response{Message: message, Retry: err != nil}, nil + message, err = e.handle() + // if err != nil { + // if message != "" { + // message += ": " + err.Error() + // } else { + // message = err.Error() + // } + // } + // return Response{Message: message, Retry: err != nil}, err + return message, err } func main() { diff --git a/handler/task.go b/handler/task.go index 03885a3..31b89f1 100644 --- a/handler/task.go +++ b/handler/task.go @@ -9,11 +9,6 @@ import ( var taskSetUpWG sync.WaitGroup -const ( - taskRetentionMin = 5 - batchSize = 12 -) - // Task - ORCID Hub affiliation registration batch task type Task struct { ID int `json:"id,omitempty"`