Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Revert "fixed hanging when python raises exception or return nothing""" #1394

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lambda/handler-runner/python-runner/PythonRunner.js
Original file line number Diff line number Diff line change
@@ -123,8 +123,7 @@ export default class PythonRunner {
const onLine = (line) => {
try {
const parsed = this._parsePayload(line.toString())

if (typeof parsed !== 'undefined') {
if (parsed) {
this.handlerProcess.stdout.readline.removeListener('line', onLine)
this.handlerProcess.stderr.removeListener('data', onErr)
return accept(parsed)
6 changes: 1 addition & 5 deletions src/lambda/handler-runner/python-runner/invoke.py
Original file line number Diff line number Diff line change
@@ -94,11 +94,7 @@ def log(self):
input = json.loads(stdin.readline())

context = FakeLambdaContext(**input.get('context', {}))

try:
result = handler(input['event'], context)
except Exception as e:
result = str(e)
result = handler(input['event'], context)

data = {
# just an identifier to distinguish between
6 changes: 4 additions & 2 deletions src/lambda/routes/invocations/InvocationsController.js
Original file line number Diff line number Diff line change
@@ -90,8 +90,10 @@ export default class InvocationsController {
}

// Checking if the result of the Lambda Invoke is a primitive string to wrap it. this is for future post-processing such as Step Functions Tasks
if (typeof result === 'string') {
result = `"${result}"`
if (result) {
if (typeof result === 'string') {
result = `"${result}"`
}
}

// result is actually the Payload.
9 changes: 0 additions & 9 deletions tests/integration/python/python2/handler.py
Original file line number Diff line number Diff line change
@@ -9,12 +9,3 @@ def hello(event, context):
"body": json.dumps(body),
"statusCode": 200,
}

def helloReturnEmptyString(event, context):
return ""

def helloReturnNothing(event, context):
return

def helloException(event, context):
raise Exception("hello-error")
46 changes: 0 additions & 46 deletions tests/integration/python/python2/python2.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { config, Lambda } from 'aws-sdk'
import { resolve } from 'path'
import fetch from 'node-fetch'
import { joinUrl, setup, teardown } from '../../_testHelpers/index.js'

jest.setTimeout(60000)

const { stringify } = JSON

// Could not find 'Python 2' executable, skipping 'Python' tests.
const _describe = process.env.PYTHON2_DETECTED ? describe : describe.skip

@@ -39,47 +36,4 @@ _describe('Python 2 tests', () => {
expect(json).toEqual(expected)
})
})

config.update({
accessKeyId: 'ABC',
secretAccessKey: 'SECRET',
region: 'us-east-1',
})

const lambda = new Lambda({
apiVersion: '2015-03-31',
endpoint: 'http://localhost:3002',
})

// lambda invocation with some cases.
;[
{
description: 'should work with python 2 with empty string',
expected: { Payload: stringify(''), StatusCode: 200 },
functionName: 'helloReturnEmptyString',
},
{
description: 'should work with python 2 without return value',
expected: { Payload: '', StatusCode: 200 },
functionName: 'helloReturnNothing',
},
{
description: 'should work with python 2 raising exception',
expected: { Payload: stringify('hello-error'), StatusCode: 200 },
functionName: 'helloException',
},
].forEach(({ description, expected, functionName }) => {
test(description, async () => {
const params = {
// ClientContext: undefined,
FunctionName: `python-2-tests-dev-${functionName}`,
InvocationType: 'RequestResponse',
// Payload: undefined,
}

const response = await lambda.invoke(params).promise()

expect(response).toEqual(expected)
})
})
})
6 changes: 0 additions & 6 deletions tests/integration/python/python2/serverless.yml
Original file line number Diff line number Diff line change
@@ -18,9 +18,3 @@ functions:
method: get
path: hello
handler: handler.hello
helloReturnEmptyString:
handler: handler.helloReturnEmptyString
helloReturnNothing:
handler: handler.helloReturnNothing
helloException:
handler: handler.helloException
9 changes: 0 additions & 9 deletions tests/integration/python/python3/handler.py
Original file line number Diff line number Diff line change
@@ -9,12 +9,3 @@ def hello(event, context):
"body": json.dumps(body),
"statusCode": 200,
}

def helloReturnEmptyString(event, context):
return ""

def helloReturnNothing(event, context):
return

def helloException(event, context):
raise Exception("hello-error")
46 changes: 0 additions & 46 deletions tests/integration/python/python3/python3.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { config, Lambda } from 'aws-sdk'
import { platform } from 'os'
import { resolve } from 'path'
import fetch from 'node-fetch'
import { joinUrl, setup, teardown } from '../../_testHelpers/index.js'

jest.setTimeout(60000)

const { stringify } = JSON

// skipping 'Python 3' tests on Windows for now.
// Could not find 'Python 3' executable, skipping 'Python' tests.
const _describe =
@@ -44,47 +41,4 @@ _describe('Python 3 tests', () => {
expect(json).toEqual(expected)
})
})

config.update({
accessKeyId: 'ABC',
secretAccessKey: 'SECRET',
region: 'us-east-1',
})

const lambda = new Lambda({
apiVersion: '2015-03-31',
endpoint: 'http://localhost:3002',
})

// lambda invocation with some cases.
;[
{
description: 'should work with python 3 with empty string',
expected: { Payload: stringify(''), StatusCode: 200 },
functionName: 'helloReturnEmptyString',
},
{
description: 'should work with python 3 without return value',
expected: { Payload: '', StatusCode: 200 },
functionName: 'helloReturnNothing',
},
{
description: 'should work with python 3 raising exception',
expected: { Payload: stringify('hello-error'), StatusCode: 200 },
functionName: 'helloException',
},
].forEach(({ description, expected, functionName }) => {
test(description, async () => {
const params = {
// ClientContext: undefined,
FunctionName: `python-3-tests-dev-${functionName}`,
InvocationType: 'RequestResponse',
// Payload: undefined,
}

const response = await lambda.invoke(params).promise()

expect(response).toEqual(expected)
})
})
})
6 changes: 0 additions & 6 deletions tests/integration/python/python3/serverless.yml
Original file line number Diff line number Diff line change
@@ -18,9 +18,3 @@ functions:
method: get
path: hello
handler: handler.hello
helloReturnEmptyString:
handler: handler.helloReturnEmptyString
helloReturnNothing:
handler: handler.helloReturnNothing
helloException:
handler: handler.helloException