1
votes

I want to test file uploading using Jmeter.

I want to upload files using 5 threads concurrently.

1 Thread successfully uploads all the files but after that all threads says file exist (which makes sense)

Is there a way i can upload all files successfully from all 5 threads, may be generate new file name each time ?

enter image description here

1
I was able to rename the file before uploading it using a beanshell code. In my case there was only 1 file though. Also this way it will rename the file on your machine, so you might need to go back to the files and rename them again before/after each test, will that work with you? If yes, are you going to run the scripts from your local machine?ararar
I see you are suggesting some manual stuff...can it not be automated by beanshell code which will rename each file for every user and upload it ? Yes i am running from local machineuser662285
The manual stuff is more like test data organizing, renaming the files to be something like file_1.pdf, file_2.pdf, file_3.xlsx ...etc. Another concern to my solution is that you will not be able to upload the files with 5 concurrent users at the same time, but one at a time, reason is that when 2 or more threads are renaming the files at the same time, only the last thread will find the files (because it will be renamed from file_1.pdf to file_5.pdf) so the other 4 threads will fail. To fix that, you will need separate files for each thread (a copy with different name will work).ararar

1 Answers

1
votes

This solution will work for the configurations that you shared, 5 concurrent users uploading 10 files each.

First of all, create separate files for each thread (you have 10 files, copy them into 50) and rename them as below

Thread1_file1_0
Thread1_file2_0
Thread1_file3_0
.
.
Thread1_file10_0
Thread2_file1_0
Thread2_file2_0
.
.
Thread5_file10_0

Then create a csv file and add file extensions in column A. Make sure that row 1 reflects the extension of Threadx_file1_0 and row 2 reflects the extension of Threadx_file2_0 file as below and save the csv file in the same folder of your jmx script

enter image description here

Now to the script configurations, add 2 counters before your POST request (which uploads the files) with below configurations

First counter

Start 0

Increment 1

Reference Name originalName

Track counter independently for each user Yes

Reset counter on each Thread Group Iteration No

Second counter

Start 1

Increment 1

Reference Name Iteration

Track counter independently for each user Yes

Reset counter on each Thread Group Iteration No

Now add a loop controller with loop count set to 10, then add another counter, OS Process Sampler and CSV Data Set Config as children of the loop controller with below configurations

Counter configurations

Start 1

Increment 1

Reference Name fileNumber

Track counter independently for each user Yes

Reset counter on each Thread Group Iteration Yes

CSV Data Set Config

Filename extensionsCSVFile.csv

Variable Names extension

OS Process Sampler configurations

Command cmd

Command parameters

/C

ren {path to your folder}\Thread${__threadNum}_file${fileNumber}_${originalName}.${extension} Thread${__threadNum}_file${fileNumber}_${Iteration}.${extension}

Each line as a separate parameter. Now use file name in your post request as below

{path}\Thread${__threadNum}_file1_${Iteration}.pdf
{path}\Thread${__threadNum}_file2_${Iteration}.pdf
.
.
{path}\Thread${__threadNum}_file10_${Iteration}.docx

This will do the job, but i suggest that you also add a way to revert the names back to Thread1_file1_0. You can do it by following the below steps

Add a BeanShell PostProcessor as a child of the OS Process Sampler with below code in the code area

props.put("lastIteration", vars.get("Iteration"));

Now add a tearDown Thread Group, then copy the loop controller with all its elements from previous above steps and paste into the tearDown Thread Group (except the BeanShell PostProcessor, remove it after you paste).

Now go the OS Process Sampler within the tearDown Thread Group and adjust the second parameter as below

ren {}\Thread${__threadNum}_file${fileNumber}_${__P(lastIteration)}.${extension} Thread${__threadNum}_file${fileNumber}_0.${extension}

Finally, just make sure that number of threads in both main thread group and tearDown Thread Group is the same, which in this case 5. The structure will be as below

enter image description here