question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object] or indefinite hang when trying to modify requestParams.body

See original GitHub issue

I’m trying to upload a file via a PUT request with no luck. As far as I can tell this is the way that it is being done in artillery-plugin-http-file-uploads. I suspect the TypeError is coming from when either artillery or request is trying to calculate the length of the request body. Is this a known issue? Has anyone been able to successfully upload a file using artillery?

artillery-plugin-http-file-uploads/index.js:

traverse(requestParams).forEach(function(o) {
    if (o && o.fromFile) {
        const filename = path.resolve(
            basePath,
            renderVariables(o.fromFile, userContext.vars));
        debug(`Updating`, o, `with`, filename);
        const stream = fs.createReadStream(filename);
        // in-place update:
        this.update(stream);
    }
});

app.ts:

import { config } from "./config";

import * as artillery from "./node_modules/artillery/lib/commands/run";
import * as fs from "fs";
import * as temp from "tmp";

let script = {
    "config": {
        "target": "http://" + config.get("pasUrl") + ":" + config.get("pasPort"),
        "phases": [
            {
                "duration": 1,
                "arrivalCount": 1
            }
        ],
        "processor": "../scenarios/scenario1.js",
        "mode": "uniform"
    },
    "scenarios": [
        {
            "flow": [
                {
                    "post": {
                        "url": "/ViewingSession",
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        "beforeRequest": "setRequestBodyForViewingSessionPost",
                        "capture": {
                            "json": "$.viewingSessionId",
                            "as": "viewingSessionId"
                        }
                    }
                },
                {
                    "put": {
                        "url": "/ViewingSession/u{{ viewingSessionId }}/SourceFile",
                        "headers": {
                            "Accusoft-Secret": "mysecretkey",
                            "Content-Type": "application/octet-stream"
                        },
                        "beforeRequest": "setRequestBodyForViewingSessionPut",
                    }
                }
            ]
        }
    ]
};

let tempfile = temp.fileSync({ "dir": "temp" });
fs.writeFileSync(tempfile.name, JSON.stringify(script, undefined, 4), { "flag": "w" });

// artillery(filename, options)
artillery(tempfile.name, {});

scenario1.ts:

export function setRequestBodyForViewingSessionPut(requestParams, context, ee, next) {
    requestParams.body = fs.createReadStream(path.join(__dirname, "..", "documents", "creating-wireframes.pdf"));

    return next(); // Artillery hangs indefinetly
}

export function setRequestBodyForViewingSessionPut2(requestParams, context, ee, next) {
    let readStream = fs.createReadStream(path.join(__dirname, "..", "documents", "creating-wireframes.pdf"));

    let bufferArray = [];

    readStream.on("data", function(data) {
        bufferArray.push(data);
    });

    readStream.on("close", function() {
        requestParams.body = Buffer.concat(bufferArray);

        return next(); // TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
    });
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hassycommented, Jun 19, 2018

@brianjenkins94 file uploads are known to work well. There’s a DIY solution here: https://github.com/shoreditch-ops/artillery/issues/320#issuecomment-329448748. If you need a solution which just works out of the box, and also works when running distributed tests from AWS, check out Artillery Pro.

0reactions
brianjenkins94commented, Jun 19, 2018

"artillery": "^1.6.0-19"

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Method Uint8Array.length called on incompatible ...
TypeError : Method Uint8Array.length called on incompatible receiver [object Object] at Buffer.get length (native) at writeFd (fs.js:1207:45) ...
Read more >
TypeError: Method get TypedArray.prototype.length called on ...
TypeError : Method get TypedArray.prototype.length called on incompatible receiver.
Read more >
JavaScript TypeError - X.prototype.y called on incompatible type
This JavaScript exception called on incompatible target (or object)” occurs if a function (on a given object), is called with a 'this' ...
Read more >
X.prototype.y called on incompatible type - Javascript MDN 文档
The JavaScript exception "called on incompatible target (or object)" occurs when a ... TypeError: Method Set.prototype.add called on incompatible receiver ...
Read more >
notebookffad25d0e2 - Kaggle
Copy & Edit 47. arrow_drop_up ... [\\]^_`{|}~\t\n\r', lower=True, split=" ") tokenizer.fit_on_texts(train['Body']) train_x ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found