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

Node packages should not be fetched #360

Closed
arichiardi opened this issue Nov 10, 2017 · 6 comments
Closed

Node packages should not be fetched #360

arichiardi opened this issue Nov 10, 2017 · 6 comments

Comments

@arichiardi
Copy link

arichiardi commented Nov 10, 2017

Hello all!

I am trying the following in my script:

import * as fs from "fs"
...

but I receive:

ERRO[0000] GoError: Get https://fs?_k6=1: dial tcp: lookup fs on 127.0.0.11:53: no such host

It seems to me that the feature (I was reading issue #167) that fetches dependencies should skip fetching node built-in modules, but I might be doing something wrong instead.

Thanks for this, it looks very nice!

@arichiardi
Copy link
Author

I have also some debug logs, and it seems my theory is not that far from reality:

DEBU[0000] Loading...                                    name=/scripts/k6sendEvent.js pwd=/go/src/github.com/loadimpact/k6
DEBU[0000] Resolved...                                   name=/scripts/k6sendEvent.js
DEBU[0000] Babel: Transformed                            t=128.073014ms
DEBU[0000] Loading...                                    name=fs pwd=/scripts
DEBU[0000] Resolved...                                   name=fs
DEBU[0000] Fetching source...                            url="https://fs?_k6=1"
DEBU[0000] Fetching source...                            url="https://fs"
ERRO[0000] GoError: Get https://fs?_k6=1: dial tcp: lookup fs on 127.0.0.11:53: no such host

@arichiardi
Copy link
Author

There is a node package package that seems to have a list of built-in modules.

@ppcano
Copy link
Contributor

ppcano commented Nov 10, 2017

k6 cannot load NodeJS API, because it does not run in NodeJS. k6 is written in go and use a JS interpreter to execute JS code.

Although you cannot import NodeJS API, you may use npm modules as described in the k6 Modules documentation.

If you want to open a file, you can use the open method, which given a file or a URL will return its contents. You have to call open outside the default function to avoid opening the file for each VU iteration.

import http from "k6/http";

const data = JSON.parse(open("./data.json"));

export default function() {
  let formData = ...;
  let res = http.post("https://httpbin.org/post", formData);
}

@arichiardi
Copy link
Author

Oh wow got it!

Where is open coming from? What if a dependency uses node calls?

May I ask you the why of mixing the two worlds? In terms of usability it does seem a bit confusing I have to say. Or maybe I did not read the docs properly and this was written all along. In any case thanks a lot for the prompt response!

@ppcano
Copy link
Contributor

ppcano commented Nov 10, 2017

Where is open coming from?

Sorry for that, there is a documentation article pending of being published.

What if a dependency uses node calls?

The Modules documentation describes that you have to browserify the npm module. Browserify will take care of the node calls.

May I ask you the why of mixing the two worlds?

JS as the scripting language for user adoption and go to achieve a decent performance.
You could read about k6 performance in this Performance comparison of Load testing tools

In terms of usability it does seem a bit confusing

I think we have to improve our documentation/communication in this aspect.

Thanks for the feedback.

I am closing the issue, let us know if you have any other question here or in stackoverflow using k6 tag

@ppcano ppcano closed this as completed Nov 10, 2017
@arichiardi
Copy link
Author

arichiardi commented Nov 14, 2017

@ppcano I tried open but still does not find the file, is it a wrapper or straight go?

const data = JSON.parse(open("./events.json"));
time="2017-11-14T20:33:13Z" level=error msg="GoError: Get htt: lookup events.json on *my-ip-address:port:* no such host"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants