How to put a customized message in K6 Check - k6

I am running a K6 tests with request.batch where number of requests can change for each test.
req = [req0, req1, req2, ...];
let res = http.batch(req);
then, I am trying to run a "check" for each request, and I use a while loop to do so.
while (i < req.length) {
check(
res[i],
{" ${i} - status 200": (r) => r.status === 200 }
);
i++;
}
however K6 accumulate all "check" tests results in a single test, as test message doesn't parse the variable I pass.
the output prints this message at the end of the test:
done [===============] 10s / 10s
✓ ${i} - status 200
I have tried to use different ways add the parameters, but no use:
{ i + " - status 200": (r) => r.status === 200 }
{' ${i} - status 200': (r) => r.status === 200 }
{` ${i} - status 200`: (r) => r.status === 200 }
{" %d - status 200", i : (r) => r.status === 200 }
I would like to know if there is any why to pass a customized message here.

Not sure if you have the answer already but for others you can use the bracket notation for assiging the property name. See the example below and the following link: How to create an object property from a variable value in JavaScript?
import http from "k6/http";
import { check } from "k6";
export default function() {
let response = http.get("https://test.loadimpact.com");
let test = "x";
check(response, {
[test + " - status 200"]: (r) => r.status === 200
});
};
This results in the following output:
done [==========================================================] 1 / 1i
✓ x - status 200
checks.....................: 100.00% ✓ 1 ✗ 0
data_received..............: 6.8 kB 15 kB/s
data_sent..................: 527 B 1.2 kB/s
http_req_blocked...........: avg=362.37ms min=362.37ms med=362.37ms max=362.37ms p(90)=362.37ms p(95)=362.37ms
http_req_connecting........: avg=138.16ms min=138.16ms med=138.16ms max=138.16ms p(90)=138.16ms p(95)=138.16ms
http_req_duration..........: avg=91.62ms min=91.62ms med=91.62ms max=91.62ms p(90)=91.62ms p(95)=91.62ms
http_req_receiving.........: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_sending...........: avg=992.2µs min=992.2µs med=992.2µs max=992.2µs p(90)=992.2µs p(95)=992.2µs
http_req_tls_handshaking...: avg=214.19ms min=214.19ms med=214.19ms max=214.19ms p(90)=214.19ms p(95)=214.19ms
http_req_waiting...........: avg=90.63ms min=90.63ms med=90.63ms max=90.63ms p(90)=90.63ms p(95)=90.63ms
http_reqs..................: 1 2.207509/s
iteration_duration.........: avg=453.99ms min=453.99ms med=453.99ms max=453.99ms p(90)=453.99ms p(95)=453.99ms
iterations.................: 1 2.207509/s
vus........................: 1 min=1 max=1
vus_max....................: 1 min=1 max=1

Related

How to fix error message in tcl script having command [exec bjobs] when no jobs are running?

when I am running a Tcl script that contains the following lines:
set V [exec bjobs ]
puts "bjobs= ${V}"
When jobs are present it's working properly but, no jobs are running it is showing an error like this:
No unfinished job found
while executing
"exec bjobs "
invoked from within
"set V [exec bjobs ]"
How to avoid this error? Please let me know how to avoid this kind of errors.
It sounds to me like the bjobs program has a non-zero exit code in this case. The exec manual page includes this example in a subsection WORKING WITH NON-ZERO RESULTS:
To execute a program that can return a non-zero result, you should wrap
the call to exec in catch and check the contents of the -errorcode
return option if you have an error:
set status 0
if {[catch {exec grep foo bar.txt} results options]} {
set details [dict get $options -errorcode]
if {[lindex $details 0] eq "CHILDSTATUS"} {
set status [lindex $details 2]
} else {
# Some other error; regenerate it to let caller handle
return -options $options -level 0 $results
}
}
This is more easily written using the try command, as that makes it
simpler to trap specific types of errors. This is done using code like
this:
try {
set results [exec grep foo bar.txt]
set status 0
} trap CHILDSTATUS {results options} {
set status [lindex [dict get $options -errorcode] 2]
}
I think you could write this as:
try {
set V [exec bjobs ]
} trap CHILDSTATUS {message} {
# Not sure how you want to handle the case where there's nothing...
set V $message
}
puts "bjobs= ${V}"
if {[catch {exec bjobs} result]} {
puts "bjobs have some issues. Reason : $result"
} else {
puts "bjobs executed successfully. Result : $result"
}
Reference : catch
Note carefully in the exec man
page:
If any of the commands in the pipeline exit abnormally or are killed or
suspended, then exec will return an error [...]
If any of the commands
writes to its standard error file and that standard error is not
redirected and
-ignorestderr is not specified, then exec will return an
error.
So if bjobs returns non-zero or prints to stderr when there are no jobs, exec needs catch or try as Donal writes.

Gatsby build webpack fail with stylis

When I run gatsby build I get this error:
failed Building static HTML for pages - 10.179s
ERROR #95313
Building static HTML failed
See our docs page for more info on this error: https://gatsby.dev/debug-html
343 | for (c = []; b < a; ++b) {
344 | for (var n = 0; n < m; ++n) {
> 345 | c[v++] = Z(d[n] + ' ', h[b], e).trim();
| ^
346 | }
347 | }
348 |
WebpackError: The module '/node_modules/canvas/build/Release/canvas.node'
- stylis.esm.js:345
node_modules/#emotion/stylis/dist/stylis.esm.js:345:1
- stylis.esm.js:151
node_modules/#emotion/stylis/dist/stylis.esm.js:151:1
- stylis.esm.js:175
node_modules/#emotion/stylis/dist/stylis.esm.js:175:1
- stylis.esm.js:286
node_modules/#emotion/stylis/dist/stylis.esm.js:286:1
- stylis.esm.js:151
node_modules/#emotion/stylis/dist/stylis.esm.js:151:1
- stylis.esm.js:175
node_modules/#emotion/stylis/dist/stylis.esm.js:175:1
- stylis.esm.js:286
node_modules/#emotion/stylis/dist/stylis.esm.js:286:1
- stylis.esm.js:151
How to solve? When run gatsby develop there is no error.
Update gatsby-config.js to contain the plugin gatsby-plugin-emotion:
module.exports = {
plugins: [
`gatsby-plugin-emotion`,
],
}
This needs a restart of the gatsby development process.
Add this snippet in the gatsby-node.js:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /canvas/,
use: loaders.null(),
},
],
},
})
}
}
There's a package that is trying to access global objects such as window or document in your SSR (Server-Side Rendering) where obviously is not defined (it even exist) because gatsby-build occurs in the Node server while gatsby develop occurs in the browser-side, where the window exists and the compilation time. With the snippet above, you are adding a null loader to the offending module when webpack transpile the code.
The rule test is a regular expression (hence the braces, /) that matches the folder name inside node_modules. The output error shows a canvas issue but you may need to change it to /stylis/

Amavisd error mail_dispatch: no recognized protocol name

OS: FreeBSD-11.1
Name: amavisd-new-2.11.0_2,1
We recently began getting these errors from amavisd reported in our maillog:
. . .
proxy-reject: END-OF-MESSAGE: 451 4.5.0 Error in processing,
id=29937-07, quar+notif FAILED:
mail_dispatch: no recognized protocol name: -2
at /usr/local/sbin/amavisd line 9638.;
. . .
Each one of these errors results from processing messages from a single domain. However, not all of the traffic from that domain generates an error.
The code section in amavisd referred to in the message reads:
9619 my $any_deliveries = 0;
9620 my $per_recip_data = $msginfo->per_recip_data;
9621 my $num_recips_notdone =
9622 scalar(grep(!$_->recip_done && (!$filter || &$filter($_)),
9623 #$per_recip_data));
9624 while ($num_recips_notdone > 0) {
9625 # a delivery method may be a scalar of a form protocol:socket_specs, or
9626 # a listref of such elements; if a list is provided, it is expected that
9627 # each entry will be using the same protocol name, otherwise behaviour
9628 # is unspecified - so just obtain the protocol name from the first entry
9629 #
9630 my(%protocols, $any_tempfail);
9631 for my $r (#$per_recip_data) {
9632 if (!$dsn_per_recip_capable) {
9633 my $recip_smtp_response = $r->recip_smtp_response; # any 4xx code ?
9634 if (defined($recip_smtp_response) && $recip_smtp_response =~ /^4/) {
9635 $any_tempfail = $recip_smtp_response . ' (' . $r->recip_addr . ')';
9636 }
9637 }
9638 if (!$r->recip_done && (!$filter || &$filter($r))) {
9639 my $proto_sockname = $r->delivery_method;
9640 defined $proto_sockname
9641 or die "mail_dispatch: undefined delivery_method";
9642 !ref $proto_sockname || ref $proto_sockname eq 'ARRAY'
9643 or die "mail_dispatch: not a scalar or array ref: $proto_sockname";
9644 for (ref $proto_sockname ? #$proto_sockname : $proto_sockname) {
9645 local($1);
9646 if (/^([a-z][a-z0-9.+-]*):/si) { $protocols{lc($1)} = 1 }
9647 else { die "mail_dispatch: no recognized protocol name: $_" }
9648 }
9649 }
9650 }
But I have no idea where the protocol name sought is obtained. Because of the error the offending message is not placed in the quarantine folder so I cannot examine it.
Is this a configuration error on our part or is this the result of a malformed email transmission? In either case, what can I do to resolve this matter?

NTLM requests in K6

I am testing the NTLM auth using the release v0.20.0-dev-dccb254. The command line to run the script below looks like:
bin\k6.exe run --vus 3 --duration 30s scripts/getOrder.js
import http from "k6/http";
import { check, sleep } from "k6";
export default function() {
let res = http.get("http://user:password#localhost:8247/orders/2377", {auth: "ntlm"});
console.log("Status code: " + res.status);
check(res, {
"status was 200": (r) => r.status == 200
});
sleep(1);
};
The first request succeeds for each VU, but the next ones are all failing. This is the output from K6:
duration: 30s, iterations: -
vus: 3, max: 3
INFO[0002] Status code: 200 -
INFO[0002] Status code: 200
INFO[0002] Status code: 200
WARN[0003] Request Failed error="Get http://user:password#localhost:8247/orders/2377: Invalid WWW-Authenticate header"
INFO[0003] Status code: 0
WARN[0003] Request Failed error="Get http://user:password#localhost:8247/orders/2377: Invalid WWW-Authenticate header"
INFO[0003] Status code: 0
...

SpringMVC/MockMVC/ jsonpath compare list of Integers

I have searched online but can't find why or how to fix it.
Problem:
My JUnit test pulls a list of user id's from a REST-API.
However, I can't seem to assert the contents of the response...
API Response:
[
{"userId":1458548702},
{"userId":1458548703},
{"userId":1458548704},
{"userId":1458548706},
{"userId":1458548707}
]
Assertion Code:
List<Integer> expectedIds = ....
ResultActions result = ...
//JSONArray and expectedIds are the same length
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$.*",
Matchers.hasSize(expectedIds.size())
)
);
//Below Fails:
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$[*].userId",
Matchers.containsInAnyOrder(expectedIds)
)
);
Error Message:
java.lang.AssertionError: JSON path "$[*].userId"
Expected: iterable over [<[1458548702, 1458548703, 1458548704, 1458548706, 1458548707]>] in any order
but: Not matched: <1458548702>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...
Libraries I'm using:
com.jayway.jsonpath json-path 2.0.0
com.jayway.jsonpath json-path-assert 2.0.0
org.mockito mockito-core 1.10.19
org.hamcrest hamcrest-all 1.3

Resources