Skip to content

Conversation

@jakowenko
Copy link
Contributor

No description provided.

@@ -0,0 +1,16 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file before was too large. Almost 15MB. If we need one with that many records, can we dynamically make them? Why do they need to be in a static file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamically creating the information was an issue I ran into due to the nature of k6 and imports, but I can revisit this.

Now that I've nailed the deleting/logging out during the actual test though, the size of this file can be drastically reduced with no impact on the test - I just have to rerun the model generator for a smaller output

const methods = require(`${__dirname}${methodsPath.slice(methodsPath.indexOf('/'))}`);

const newFile = await new StringPrompt({
initial: 'tests/k6/scripts/alpha.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we default this to something from the input file? If the input file is expressTemplate.json, we can default the filename to something like expressTemplate.k6.js

let methodUrl = Object.keys(methods.routes)[i];

for (let j = 0; j < methods.routes[methodUrl].length; j++) {
const current = methods.routes[methodUrl][j];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and other places you can just do:

const { path, uniquePayload } = methods.routes[methodUrl][j];

}

if (!uniqueObj) {
uniqueObj = '""';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because replace-in-file doesn't keep the first set of quotes - so when there was no unique object to define, I would end up with something like uniqueObj = ; which would give me an error

let methodUrl = Object.keys(methods.routes)[i];

for (let j = 0; j < methods.routes[methodUrl].length; j++) {
const current = methods.routes[methodUrl][j];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { tag } = methods.routes[methodUrl][j];

writeVuObj = `let vuObj = ${JSON.stringify(vuObj)};\n\n`;

// PARSE THROUGH ALL ROUTES AND ADD TO MAIN CONTENT - WITHIN DEFAULT FUNCTION
const baseUrl = methods['baseUrl'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { baseUrl } = methods;

let fullPath;

for (let j = 0; j < methods.routes[methodUrl].length; j++) {
let current = methods.routes[methodUrl][j];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

customImport = `const SLEEP_DURATION = ${methods['sleep']}\nconst uniqueData = JSON.parse(open('${uniqueFile}'))`;
uniqueObj = `'${uniqueFile.slice(uniqueFile.lastIndexOf('/') + 1, -5)}'`;
}
if (!customImport) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something like this for customImport.

customImport = uniquePayload ? `const SLEEP_DURATION = ${methods['sleep']}\nconst uniqueData = JSON.parse(open('${uniqueFile}')) : `const SLEEP_DURATION = ${methods['sleep']}`

Also, I would try to move the const SLEEP_DURATION to the template. And only set the value of it from this generate file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't do the exact code example you gave for custom import because of where it was in the code, but I did refactor to something that looks cleaner! And sleep duration is also a separate prompt to replace a value in the template now

payload = [];
tagName = '${tag}Res';`;

if (custom) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does custom do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom property indicates if there is something dynamic in the path, for example a delete path requiring an ${id}. I parse the full path differently in this case

case 'createUser':
case 'login':
case 'logout':
case 'post':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to get fancy, a lot of this can probably be put into a method template file then find and replace similar to what you are doing with the base k6 one.

- prompt for sleep
- initial new file name upgraded
- more unique data to use
- generated report has dynamic name and path
- docs update
- general clean up
- routes can go in any logical order
- summary prompt upgrade
- auth added on login and set to null on logout
- no more floating `false;`
- setNull property to remove id and token
- docs update
- less unique data needed
- now we'll need as many unique items as there are simultaneous VU's
- update to account for zero indexing
- moved unique/user.json and adjusted checks
- renamed summary
- use path.resolve to avoid relative pathing issues
- rename 'path' in methods file to fix naming overlap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants