k6 change my port and protocol

Created on 27 Mar 2019  路  3Comments  路  Source: loadimpact/k6

I wrote a first test, running inside a docker-compose, targeting http://web:8000

Second test target an IRL server, with https on port 443.

/*global __ENV : true  */
/*eslint no-console: off */
import http from "k6/http";
import { check } from "k6";


export function setup() {
    let t = __ENV.target;
    if (t === undefined) {
        t = "example.com";
    }
    if (! t.startsWith("http")) {
        t = `https://${t}`
    }
    return {
        "target": t,
    };
}

export default function(conf) {
    console.log(JSON.stringify(conf));
    console.log(conf.target);
    console.log(`${conf.target}/societe`);
    const res = http.get(`${conf.target}/societe`);
    check(res, {
        "status is 200": (r) => r.status === 200,
    });
    res.html('.read-more').each((idx, el) => {
        const uri = el.parentNode().getAttribute('href');
        const url = `${conf.target}${uri}`;
        console.log(url);
        let res = http.get(url);
        check(res, {
            "status is 200": (r) => r.status === 200,
        });
    })
}

The console.log display correct protocol and port, but k6 yield an error about http and 8000 port.

INFO[0000] https://my-real-website.com/societe
WARN[0001] Request Failed                                error="Get http://my-real-website.com:8000/societe/: dial tcp <my real ip>:8000: connect: connection refused"

The server has no redirection, curl -v works well.

$ k6 version
k6 v0.24.0

Most helpful comment

it's look a PBCAK trouble.

All 3 comments

Hm ... I can't reproduce this inside docker or outside.

Can you please :

  1. Set redirects to 0 for the http.get (see first example (sorry can't link to it directly))
  2. Maybe try with http://test.loadimpact.com/ , even without changing the res.html part
  3. Try running with --http-debug - it will print headers of requests and responses.
  4. Run curl from inside the docker:
docker run -ti --rm  --entrypoint /bin/sh  loadimpact/k6:0.24.0
// after that you need to install curl
apk add curl
// and then run it with your site
curl https://my-real.website.com

p.s. You probably want to remove the ! in the second if, the one with startsWith

it's look a PBCAK trouble.

It is.

Thanks for the explicit redirects: 0. Sorry for the noise.

Was this page helpful?
0 / 5 - 0 ratings