-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce assert() - an angry check() #3406
Comments
Hi @netikras! The See an example below: import http from 'k6/http';
import { check, fail } from 'k6';
const assert = (val, set, tags) => {
if (!check(val, set, tags)) {
fail('assertion failed');
}
}
export default function () {
const res = http.get('https://httpbin.test.k6.io');
assert(
res,
{
'response code was 200': (res) => res.status == 200,
'body size was 1234 bytes': (res) => res.body.length == 1234,
},
{ myTag: "I'm a tag" }
);
} Does that solve your need? |
@olegbespalov of course it could! I bet But since you created a Also, I think And I see that And your proposed solution doesn't exactly solve the problem, as (I think) it doesn't say which checks failed (body size? status code?) I can continue my list of explanations on why I think |
While we're at it, I think implementing And IMO it sounds logical.
Same with |
First of all, I'm trying to understand the need and the reason why you think that it should be implemented directly in k6 (golang). For example, we have a k6chaijs library that implements a BDD assertions approach using pure JavaScript https://k6.io/docs/javascript-api/jslib/k6chaijs/. So my suggestion was just a quick example, but by using JavaScript you can try to create the method that serves your needs. |
@olegbespalov I'd say convenience and removing the necessity to always import a 3rd-party library in (almost) every script to write a simple e2e test flow with basic flow control, w/o reducing readability. Again, I'm referring to the
https://k6.io/docs/javascript-api/k6/fail/ I understand that you are trying to avoid bloating the k6 code by excessive features.
HP LoadRunner has it built-in locust and k6 don't have it, unfortunately |
Consider the diff -import { assert } from 'k6';
+import { assert } from 'https://jslib.k6.io/k6-utils/2.3.0/index.js'; // this not yet exists Or using a local module that implements an So neither readability nor maintainability is actually dramatically decreasing. In the end, it is just about the difference in import.
There is no need to focus on the
Yes, you're right here. But also, there should be a significant reason (like performance implications) to have this implemented in the core/golang.
I hear you and accept your needs, but I'm trying to point out that k6 can solve your needs already by using JavaScript, moreover, it could be tailored specially for you and your special case. And it could be implemented and used independently of the k6 release. On another note, I fully agree that looking for workarounds could be frustrating. So at least, we could maybe try to provide a minimal example of the @grafana/k6-core if you have something to add or have another opinion please chime in. |
ref #4067 |
Feature Description
If a failed transaction's result is required for subsequent transactions in the iteration (e.g. if login() failed), there's no point in executing the rest of the txs. So we need a simple failure mechanism.
check() does not fail the iteration, it only records failures (if any).
I propose introducing a separate validation function, that does what check() does, except it fail()s instead of returning
false
.Suggested Solution (optional)
check( val, sets, [tags] )
tocheckOrFail( val, **fail: boolean**, sets, [tags] )
check( val, sets, [tags] )
that only doescheckOrFail( val, false, sets, [tags] )
assert( val, sets, [tags] )
that only doescheckOrFail( val, true, sets, [tags] )
In case an error is thrown, it should contain a list of failures, i.e.:
I'm not that fluent in GO to implement it myself...yet. But I see where it should be changed:
https://github.com/grafana/k6/blob/master/js/modules/k6/k6.go
Already existing or connected issues / PRs (optional)
No response
The text was updated successfully, but these errors were encountered: