-
Notifications
You must be signed in to change notification settings - Fork 3
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
chore(k6): Fix parsing error during k6 run in ci #1158
Changes from all commits
ab4096f
6934715
365efe4
10e060d
cb841c2
2100b00
e900523
082445f
0042da9
2940b31
7a4a509
d8fc0c4
b6adde2
92a5164
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ function resolveParams(defaultParams, params) { | |
} | ||
|
||
function getServiceOwnerRequestParams(params = null, tokenOptions = null) { | ||
|
||
params = params || {}; | ||
const headers = params.Headers || {}; | ||
const hasOverridenAuthorizationHeader = headers.Authorization !== undefined; | ||
|
@@ -62,6 +62,15 @@ export function postSO(url, body, params = null, tokenOptions = null) { | |
return http.post(baseUrlServiceOwner + url, body, getServiceOwnerRequestParams(params, tokenOptions)); | ||
} | ||
|
||
export function postBatchSO(batch) { | ||
const processedBatch = batch.map(([url, body, params]) => { | ||
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }}); | ||
return ['POST', baseUrlServiceOwner + url, JSON.stringify(body), getServiceOwnerRequestParams(params)]; | ||
}); | ||
|
||
return http.batch(processedBatch); | ||
} | ||
Comment on lines
+65
to
+72
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. 🧹 Nitpick (assertive) Good implementation, with suggestions for improvement The
Here's a suggested implementation incorporating these improvements: export function batchRequestsSO(batch, tokenOptions = null) {
if (!Array.isArray(batch)) {
throw new Error('batch must be an array');
}
const processedBatch = batch.map(([method, url, body, params]) => {
if (!['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
throw new Error(`Unsupported HTTP method: ${method}`);
}
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }});
return [
method,
baseUrlServiceOwner + url,
body ? JSON.stringify(body) : null,
getServiceOwnerRequestParams(params, tokenOptions)
];
});
return http.batch(processedBatch);
} This implementation adds input validation, supports multiple HTTP methods, and includes the |
||
|
||
export function postSOAsync(url, body, params = null, tokenOptions = null) { | ||
body = maybeStringifyBody(body); | ||
params = extend(true, {}, params, { headers: { 'Content-Type': 'application/json' }}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ export { | |
getSO, | ||
postSO, | ||
postSOAsync, | ||
postBatchSO, | ||
putSO, | ||
patchSO, | ||
deleteSO, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { describe, expect, expectStatusFor, postSO, postSOAsync, purgeSO } from '../../common/testimports.js' | ||
import { describe, expect, expectStatusFor, postSO, postBatchSO, purgeSO } from '../../common/testimports.js' | ||
import { default as dialogToInsert } from './testdata/01-create-dialog.js'; | ||
|
||
export default function () { | ||
|
@@ -16,14 +16,14 @@ export default function () { | |
|
||
describe('Attempt to add a few child entities concurrently', async () => { | ||
|
||
let promises = []; | ||
let batch = []; | ||
|
||
for (let i=0; i<10; i++) { | ||
let activity = { type: "Information", performedBy: { actorType: "serviceOwner" }, description: [ { value: i.toString(), languageCode: "nb"}]}; | ||
promises.push(postSOAsync('dialogs/' + dialogId + '/activities?' + i, activity)) | ||
batch.push(['dialogs/' + dialogId + '/activities?' + i, activity]); | ||
} | ||
|
||
const results = await Promise.all(promises); | ||
const results = postBatchSO(batch); | ||
|
||
Comment on lines
+19
to
+26
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. 🧹 Nitpick (assertive) LGTM: Improved concurrency test implementation with minor suggestions The changes effectively address the PR objective of fixing the output order from concurrency tests by using a batch operation instead of individual promises. This simplifies the concurrency handling and should resolve the parsing issues. However, there are a few minor improvements we can make:
batch.push([`dialogs/${dialogId}/activities?${i}`, activity]);
const batch = [];
// ...
for (let i=0; i<10; i++) {
const activity = { /* ... */ };
// ...
} These changes will improve code readability and follow best practices. 🧰 Tools🪛 Biome
|
||
// Cleanup here, as we're in another thread | ||
purgeSO('dialogs/' + dialogId); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default function (){ | |
|
||
describe ('Attempt to create dialog with invalid URI', () => { | ||
let dialog = dialogToInsert(); | ||
dialog.process = '?? ?'; | ||
dialog.process = 'inval|d'; | ||
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. 🧹 Nitpick (assertive) LGTM! Consider enhancing test coverage. The change from To further improve the test case:
Would you like assistance in implementing these suggestions? |
||
let r = postSO('dialogs', dialog) | ||
expectStatusFor(r).to.equal(400); | ||
expect(r, 'response').to.have.validJsonBody(); | ||
|
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.
🧹 Nitpick (assertive)
LGTM: Improved Process property validation.
The changes to the Process property validation are good improvements:
IsValidUri()
likely provides a more comprehensive check for well-formed URIs.Constants.DefaultMaxUriLength
is a good practice to prevent issues with extremely long URIs.These changes align well with the PR objective of addressing the parsing issue related to invalid URI tests.
Consider adding a comment explaining the purpose of
Constants.DefaultMaxUriLength
for better code documentation. For example: