-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: make test variables and correlation variables defined under a containing name #112
Changes from all commits
3e71590
2d43781
8cb3584
eda1f49
69cd986
4194e5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,9 +208,8 @@ const extractCorrelationRegex = ( | |
} | ||
|
||
const getCorrelationVariableSnippet = (uniqueId: number | undefined) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it really be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I don't think it can be undefined, the type system there will need to be improved because we will always be having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a PR here: #114 |
||
return `let correl_${uniqueId} | ||
if (match) { | ||
correl_${uniqueId} = match[1] | ||
return `if (match) { | ||
correlation_vars[${uniqueId}] = match[1] | ||
}` | ||
} | ||
|
||
|
@@ -470,7 +469,7 @@ const extractCorrelationJsonBody = ( | |
: `.${selector.path}` | ||
|
||
const correlationExtractionSnippet = ` | ||
let correl_${uniqueId} = resp.json()${json_path}` | ||
correlation_vars[${uniqueId}] = resp.json()${json_path}` | ||
return { | ||
extractedValue, | ||
correlationExtractionSnippet: correlationExtractionSnippet, | ||
|
@@ -528,7 +527,7 @@ if (import.meta.vitest) { | |
} | ||
|
||
const correlationExtractionSnippet = ` | ||
let correl_1 = resp.json().user_id` | ||
correlation_vars[1] = resp.json().user_id` | ||
const expectedResult = { | ||
extractedValue: '444', | ||
correlationExtractionSnippet: correlationExtractionSnippet, | ||
|
@@ -554,9 +553,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.begin}(.*?)${selector.end}') | ||
match = resp.body.match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: 'bob', | ||
|
@@ -588,9 +586,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.begin}(.*?)${selector.end}') | ||
match = resp.headers["${canonicalHeaderKey('Content-type')}"].match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: '/', | ||
|
@@ -622,9 +619,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.begin}(.*?)${selector.end}') | ||
match = resp.url.match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: 'v1', | ||
|
@@ -650,9 +646,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.regex}') | ||
match = resp.body.match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: 'bob', | ||
|
@@ -678,9 +673,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.regex}') | ||
match = resp.headers["${canonicalHeaderKey('Content-type')}"].match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: '/', | ||
|
@@ -711,9 +705,8 @@ let correl_1 = resp.json().user_id` | |
const correlationExtractionSnippet = ` | ||
regex = new RegExp('${selector.regex}') | ||
match = resp.url.match(regex) | ||
let correl_1 | ||
if (match) { | ||
correl_1 = match[1] | ||
correlation_vars[1] = match[1] | ||
}` | ||
const expectedResult = { | ||
extractedValue: 'v1', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently defined outside of the default function, it makes it more readable but I'm not sure if it's the way we want to do it.
For comparison I left the the CORRELATION_VARS inside the default function to see how it would be when defined inside the default function, do you think it's better to have them defined outside of inside the default function ?
For correlation it doesn't change much as it's a single line, for test variables we are defining them on script generation so the list might be long 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote to keep outside of default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside of the default function makes sense because it's the scope they're being used, however, as you pointed out that it might get long, I believe leaving then outside makes it cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether the placement really makes any difference, but conceptually, it feels like correlation vars should definitely be inside the default function, as it is what k6 docs refer to as
VU code
(with the outside code being calledinit code
). Correlated values are meant to be scoped to the VU/iteration, so having them inside the default function feels natural.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yap, if we also consider the logic, having it inside means that it is always reset to the empty state on start of iteration, while having it global means we would be leaving leftover status, and that would be a bug.
So globally defined makes sense only for the Test variables 👍