-
-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acac5bb
commit f662dc5
Showing
8 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/lambda-run-mode/worker-threads/reload-handler/reload-handler.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import assert from 'node:assert' | ||
import { dirname, resolve } from 'node:path' | ||
import { env } from 'node:process' | ||
import { fileURLToPath } from 'node:url' | ||
import { promisify } from 'node:util' | ||
import { | ||
joinUrl, | ||
setup, | ||
teardown, | ||
} from '../../../integration/_testHelpers/index.js' | ||
|
||
const setTimeoutPromise = promisify(setTimeout) | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
describe.only('run mode with worker threads', function desc() { | ||
beforeEach(() => | ||
setup({ | ||
servicePath: resolve(__dirname), | ||
}), | ||
) | ||
|
||
afterEach(() => teardown()) | ||
|
||
it('should always create a new lambda instance', async () => { | ||
const url = joinUrl(env.TEST_BASE_URL, 'dev/foo') | ||
|
||
const results = [] | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
for (const _ of Array(100)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await setTimeoutPromise(10) | ||
results.push(fetch(url)) | ||
} | ||
|
||
const responses = await Promise.all(results) | ||
|
||
responses.forEach((response) => { | ||
assert.equal(response.status, 200) | ||
}) | ||
|
||
const jsons = await Promise.all( | ||
responses.map((response) => response.json()), | ||
) | ||
|
||
jsons.forEach((json) => { | ||
assert.deepEqual(json, 1) | ||
}) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
tests/lambda-run-mode/worker-threads/reload-handler/serverless.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
service: run-mode-tests | ||
|
||
configValidationMode: error | ||
|
||
plugins: | ||
- ../../../../ | ||
|
||
custom: | ||
serverless-offline: | ||
reloadHandler: true | ||
|
||
provider: | ||
memorySize: 128 | ||
name: aws | ||
region: us-east-1 # default | ||
runtime: nodejs16.x | ||
stage: dev | ||
versionFunctions: false | ||
|
||
functions: | ||
foo: | ||
events: | ||
- http: | ||
method: get | ||
path: foo | ||
handler: src/handler.foo |
14 changes: 14 additions & 0 deletions
14
tests/lambda-run-mode/worker-threads/reload-handler/src/handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const { stringify } = JSON | ||
|
||
let counter = 0 | ||
|
||
exports.foo = async function foo() { | ||
counter += 1 | ||
|
||
return { | ||
body: stringify(counter), | ||
statusCode: 200, | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/lambda-run-mode/worker-threads/reload-handler/src/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |