Skip to content

"azure-functions.test.js" test failure: Syntax error: "(" unexpected #3279

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

Closed
trentm opened this issue Apr 20, 2023 · 6 comments · Fixed by #3307
Closed

"azure-functions.test.js" test failure: Syntax error: "(" unexpected #3279

trentm opened this issue Apr 20, 2023 · 6 comments · Fixed by #3307
Assignees
Labels
8.9-candidate agent-nodejs Make available for APM Agents project planning.
Milestone

Comments

@trentm
Copy link
Member

trentm commented Apr 20, 2023

Recently, there has been a new failure in the azure-functions test:

node_tests_1     | running test: cd . && node --unhandled-rejections=strict test/instrumentation/azure-functions/azure-functions.test.js > test_output/test-instrumentation-azure-functions-azure-functions.test.js.tap 2&>1
node_tests_1     |
node_tests_1     | TAP version 13
node_tests_1     | # SKIP setup: npm ci (in /app/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp)
node_tests_1     | # azure functions
node_tests_1     | # setup
node_tests_1     | # mock APM apmServerUrl: http://localhost:43399
node_tests_1     | # setup: "func start" for AJsAzureFnApp fixture
node_tests_1     | # ["func start" stderr] /app/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func: 1: Syntax error: "(" unexpected
node_tests_1     | not ok 1 "func start" failed early: code=2
node_tests_1     |   ---
node_tests_1     |     operator: fail
node_tests_1     |     at: ChildProcess.onEarlyClose (/app/test/instrumentation/azure-functions/azure-functions.test.js:484:9)
node_tests_1     |     stack: |-
node_tests_1     |       Error: "func start" failed early: code=2
node_tests_1     |           at Test.assert [as _assert] (/app/node_modules/tape/lib/test.js:312:48)
node_tests_1     |           at Test.bound [as _assert] (/app/node_modules/tape/lib/test.js:95:17)
node_tests_1     |           at Test.fail (/app/node_modules/tape/lib/test.js:406:7)
node_tests_1     |           at Test.bound [as fail] (/app/node_modules/tape/lib/test.js:95:17)
node_tests_1     |           at ChildProcess.onEarlyClose (/app/test/instrumentation/azure-functions/azure-functions.test.js:484:9)
node_tests_1     |           at ChildProcess.emit (node:events:513:28)
node_tests_1     |           at maybeClose (node:internal/child_process:1091:16)
node_tests_1     |           at ChildProcess._handle.onexit (node:internal/child_process:302:5)
node_tests_1     |   ...
node_tests_1     | # make requests
node_tests_1     | ok 2 there is no fnAppProc # SKIP
node_tests_1     | # check all APM events
node_tests_1     | ok 3 there is no fnAppProc # SKIP
node_tests_1     | # teardown
node_tests_1     |
node_tests_1     | 1..3
node_tests_1     | # tests 3
node_tests_1     | # pass  2
node_tests_1     | # fail  1
node_tests_1     |
node_tests_1     |
node_tests_1     | /app/test/test.js:224
node_tests_1     |     if (err) throw err
node_tests_1     |              ^
node_tests_1     |
node_tests_1     | Error: non-zero error code
node_tests_1     |     at WriteStream.onClose (/app/test/test.js:86:25)
node_tests_1     |     at WriteStream.emit (node:events:513:28)
node_tests_1     |     at emitCloseNT (node:internal/streams/destroy:132:10)
node_tests_1     |     at process.processTicksAndRejections (node:internal/process/task_queues:81:21) {
node_tests_1     |   code: 'ENONZERO',
node_tests_1     |   exitCode: 1
node_tests_1     | }

This started happening yesterday on the #3274 PR, e.g. https://github.com/elastic/apm-agent-nodejs/actions/runs/4753789197/jobs/8450388109

It is reproducible in a docker test run via: .ci/scripts/test.sh -b release 18. I'm not yet sure if it is related to Node v18... or perhaps a particular version of node v18. The main relevant error output is:

node_tests_1     | # ["func start" stderr] /app/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func: 1: Syntax error: "(" unexpected
node_tests_1     | not ok 1 "func start" failed early: code=2
@trentm trentm self-assigned this Apr 20, 2023
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Apr 20, 2023
@trentm
Copy link
Member Author

trentm commented Apr 20, 2023

This is due to Azure/azure-functions-core-tools#3335

azure-functions-core-tools (used by "test/instrumentation/azure-functions/fixtures/AJsAzureFnApp" for testing) includes a post-install script, that downloads and installs some binaries. Presumably those binaries are node-version dependent, because the binaries work when installed for node 16.x, but are corrupt when installed for node 18.x or 20.x.

By "corrupt" I mean it won't execute:

root@2b4ffd338a55:/app# ./node_modules/.bin/func
/app/node_modules/azure-functions-core-tools/bin/func: 2: Syntax error: Unterminated quoted string

workaround

As a workaround for now, I'll skip AF testing for those node versions.

trentm added a commit that referenced this issue Apr 20, 2023
Just skip them until Azure/azure-functions-core-tools#3335
is resolved.

This also bumps the azure-functions-core-tools dep and sets up
dependabot for that package.

Refs: #3279
trentm added a commit that referenced this issue Apr 20, 2023
Just skip them until Azure/azure-functions-core-tools#3335
is resolved.

This also bumps the azure-functions-core-tools dep and sets up
dependabot for that package.

Refs: #3279
@trentm trentm added this to the 8.9 milestone Apr 24, 2023
@trentm
Copy link
Member Author

trentm commented Apr 27, 2023

The issue in azure-functions-core-tools is fixed, but we need to wait for a release after
'4.0.5095': '2023-03-27T15:24:07.673Z'

@trentm
Copy link
Member Author

trentm commented Apr 27, 2023

note to self: enode9

@trentm
Copy link
Member Author

trentm commented May 2, 2023

There is a new release yesterday that should resolve this:

% npm info azure-functions-core-tools time
...
  '4.0.5095': '2023-03-27T15:24:07.673Z',
  '4.0.5148': '2023-05-01T20:51:53.554Z'
}

However, .ci/scripts/test.sh -b release 18 still fails for me:

% .ci/scripts/test.sh -b release 18
...
node_tests_1  | running test: cd . && node --unhandled-rejections=strict test/instrumentation/azure-functions/azure-functions.test.js > test_output/test-instrumentation-azure-functions-azure-functions.test.js.tap 2&>1
node_tests_1  |
node_tests_1  | TAP version 13
node_tests_1  | # SKIP setup: npm ci (in /app/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp)
node_tests_1  | # azure functions
node_tests_1  | # setup
node_tests_1  | # mock APM apmServerUrl: http://localhost:44707
node_tests_1  | # setup: "func start" for AJsAzureFnApp fixture
node_tests_1  | # ["func start" stderr] /app/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func: 2: Syntax error: Unterminated quoted string
node_tests_1  | not ok 1 "func start" failed early: code=2
node_tests_1  |   ---
node_tests_1  |     operator: fail
node_tests_1  |     at: ChildProcess.onEarlyClose (/app/test/instrumentation/azure-functions/azure-functions.test.js:484:9)
node_tests_1  |     stack: |-
node_tests_1  |       Error: "func start" failed early: code=2
node_tests_1  |           at Test.assert [as _assert] (/app/node_modules/tape/lib/test.js:312:48)
node_tests_1  |           at Test.bound [as _assert] (/app/node_modules/tape/lib/test.js:95:17)
node_tests_1  |           at Test.fail (/app/node_modules/tape/lib/test.js:406:7)
node_tests_1  |           at Test.bound [as fail] (/app/node_modules/tape/lib/test.js:95:17)
node_tests_1  |           at ChildProcess.onEarlyClose (/app/test/instrumentation/azure-functions/azure-functions.test.js:484:9)
node_tests_1  |           at ChildProcess.emit (node:events:513:28)
node_tests_1  |           at maybeClose (node:internal/child_process:1091:16)
node_tests_1  |           at ChildProcess._handle.onexit (node:internal/child_process:302:5)
node_tests_1  |   ...
node_tests_1  | # make requests
node_tests_1  | ok 2 there is no fnAppProc # SKIP
node_tests_1  | # check all APM events
node_tests_1  | ok 3 there is no fnAppProc # SKIP
node_tests_1  | # teardown
node_tests_1  |
node_tests_1  | 1..3
node_tests_1  | # tests 3
node_tests_1  | # pass  2
node_tests_1  | # fail  1
node_tests_1  |
node_tests_1  |
node_tests_1  | /app/test/test.js:227
node_tests_1  |     if (err) throw err
node_tests_1  |              ^
node_tests_1  |
node_tests_1  | Error: non-zero error code
node_tests_1  |     at WriteStream.onClose (/app/test/test.js:86:25)
node_tests_1  |     at WriteStream.emit (node:events:513:28)
node_tests_1  |     at emitCloseNT (node:internal/streams/destroy:132:10)
node_tests_1  |     at process.processTicksAndRejections (node:internal/process/task_queues:81:21) {
node_tests_1  |   code: 'ENONZERO',
node_tests_1  |   exitCode: 1
node_tests_1  | }
node_tests_1  |
node_tests_1  | Node.js v18.16.0
...
docker_node_tests_1 exited with code 1
Aborting on container exit...
1

So I'm not sure what is going on there.

trentm added a commit that referenced this issue May 2, 2023
This removes the workaround added in #3281.
The core issue was fixed in [email protected]

Fixes: #3279
@trentm
Copy link
Member Author

trentm commented May 2, 2023

The repro I had on the source issue no longer reproduces so I think the root issue is fixed:

...

root@919fe8daffef:/app# ./node_modules/.bin/func
Azure Functions Core Tools
Core Tools Version:       4.0.5148 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.17.3.20392
...

root@919fe8daffef:/app# file ./node_modules/azure-functions-core-tools/bin/func
./node_modules/azure-functions-core-tools/bin/func: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=9235fcd6f9a2c78e1633b322390bc73968b03b91, for GNU/Linux 2.6.32, stripped

... I needed to update "test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/package-lock.json" to the new [email protected]. I've done this in #3307

@trentm
Copy link
Member Author

trentm commented May 2, 2023

There is now a failure with 14.0.0 tests that is similar.

https://github.com/elastic/apm-agent-nodejs/actions/runs/4864785118/jobs/8674262926?pr=3307

running test: cd . && node --unhandled-rejections=strict test/instrumentation/azure-functions/azure-functions.test.js > test_output/test-instrumentation-azure-functions-azure-functions.test.js.tap 2&>1

TAP version 13
# setup: npm ci (in /home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp)
ok 1 "npm ci" succeeded (took 2.394s)
# azure functions
/home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/test.js:224
    if (err) throw err
             ^

Error: non-zero error code
    at WriteStream.onClose (/home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/test.js:86:25)
    at WriteStream.emit (events.js:315:20)
    at emitCloseNT (internal/streams/destroy.js:77:10)
    at processTicksAndRejections (internal/process/task_queues.js:83:21) {
  code: 'ENONZERO',
  exitCode: 1
}
# setup
# mock APM apmServerUrl: http://localhost:45377
# setup: "func start" for AJsAzureFnApp fixture
# ["func start" stderr] events.js:292
# |      throw er; // Unhandled 'error' event
# |      ^
# |
# |Error: spawn /home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func ENOENT
# |    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
# |    at onErrorNT (internal/child_process.js:468:16)
# |    at processTicksAndRejections (internal/process/task_queues.js:84:21)
# |Emitted 'error' event on ChildProcess instance at:
# |    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
# |    at onErrorNT (internal/child_process.js:468:16)
# |    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
# |  errno: -2,
# |  code: 'ENOENT',
# |  syscall: 'spawn /home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func',
# |  path: '/home/runner/work/apm-agent-nodejs/apm-agent-nodejs/test/instrumentation/azure-functions/fixtures/AJsAzureFnApp/node_modules/azure-functions-core-tools/bin/func',
# |  spawnargs: [ 'start' ]
# |}
not ok 2 "func start" failed early: code=1
...

I suspect the [email protected] release broke something here. Our tests with the latest node 14 work.
The change in azure-functions-core-tools was to change the npm package used by its "lib/install.js" postinstall script to unzip the downloaded https://functionscdn.azureedge.net/public/4.0.5148/Azure.Functions.Cli.linux-x64.4.0.5148.zip archive. It is using "extract-zip"... which says it supports "node": ">= 10.17.0". My total guess is some bug with node v14.0.0 that breaks this extraction. However, this isn't work pursuing.

Workaround: I'll just change to skip testing for 14.0.0. Ideally we'd know a specific 14.x.y version where this starts breaking, but again, it isn't worth the time pursuing, IMHO.

trentm added a commit that referenced this issue May 3, 2023
This changes the workaround added in #3281.
The core issue with testing with node >=18.x was fixed in [email protected]

However, an issue testing with node v14.0.0 was introduced. We work around this by
just not testing with node v14.0.0. Testing with the latest node v14.x passes.

Refs: #3281
Fixes: #3279
trentm added a commit that referenced this issue May 16, 2023
This changes the workaround added in #3281.
The core issue with testing with node >=18.x was fixed in [email protected]

However, an issue testing with node v14.0.0 was introduced. We work around this by
just not testing with node v14.0.0. Testing with the latest node v14.x passes.

Refs: #3281
Fixes: #3279
PeterEinberger pushed a commit to fpm-git/apm-agent-nodejs that referenced this issue Aug 20, 2024
…c#3281)

Just skip them until Azure/azure-functions-core-tools#3335
is resolved.

This also bumps the azure-functions-core-tools dep and sets up
dependabot for that package.

Refs: elastic#3279
PeterEinberger pushed a commit to fpm-git/apm-agent-nodejs that referenced this issue Aug 20, 2024
This changes the workaround added in elastic#3281.
The core issue with testing with node >=18.x was fixed in [email protected]

However, an issue testing with node v14.0.0 was introduced. We work around this by
just not testing with node v14.0.0. Testing with the latest node v14.x passes.

Refs: elastic#3281
Fixes: elastic#3279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.9-candidate agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant