Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
webServer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
webServer
Commits
f80984c6
Commit
f80984c6
authored
Oct 24, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add K6 Tests
parent
1b85ee98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
0 deletions
+122
-0
testHeavyTask.js
K6TestsScripts/testHeavyTask.js
+39
-0
testParallelTasks.js
K6TestsScripts/testParallelTasks.js
+54
-0
testSingleTaskResponse.js
K6TestsScripts/testSingleTaskResponse.js
+29
-0
No files found.
K6TestsScripts/testHeavyTask.js
0 → 100644
View file @
f80984c6
import
http
from
'k6/http'
;
import
{
check
}
from
'k6'
;
import
{
sleep
}
from
'k6'
;
// Define test configuration
export
let
options
=
{
vus
:
100
,
// Number of virtual users (parallel requests)
duration
:
'30s'
,
// Duration to run the test
};
export
default
function
()
{
// Define The target Java server URL
const
url
=
'http://localhost:8000/'
;
// Get a random task and input
const
task
=
{
taskName
:
'TaskPrimeNumbers'
,
input
:
'100000'
};
const
payload
=
`
${
task
.
taskName
}
&
${
task
.
input
}
`
;
// Define request headers
const
params
=
{
headers
:
{
'Content-Type'
:
'application/plain-text'
,
},
};
// Send POST request with random task and input
let
res
=
http
.
post
(
url
,
payload
,
params
);
// Check if the request succeeded (HTTP status 200)
check
(
res
,
{
'status was 200'
:
(
r
)
=>
r
.
status
===
200
,
});
// wait for 1 second between requests
sleep
(
0.4
);
}
K6TestsScripts/testParallelTasks.js
0 → 100644
View file @
f80984c6
import
http
from
'k6/http'
;
import
{
check
}
from
'k6'
;
import
{
sleep
}
from
'k6'
;
// Define test configuration
export
let
options
=
{
vus
:
100
,
// Number of virtual users (parallel requests)
duration
:
'60s'
,
// Duration to run the test
};
// Array of task names and inputs
const
tasks
=
[
{
taskName
:
'TaskBubbleSort'
,
input
:
'4,1,3,2,5'
},
{
taskName
:
'TaskSum'
,
input
:
'9,3,7,1,6'
},
{
taskName
:
'TaskFactorial'
,
input
:
'5'
},
{
taskName
:
'TaskPrimeNumbers'
,
input
:
'28799'
},
{
taskName
:
'TaskFibonacci'
,
input
:
'10'
},
{
taskName
:
'TaskGeometricMean'
,
input
:
'2,3,4,5'
},
];
function
getRandomTask
()
{
let
randomIndex
=
Math
.
floor
(
Math
.
random
()
*
tasks
.
length
);
return
tasks
[
randomIndex
];
}
export
default
function
()
{
// Define The target Java server URL
const
url
=
'http://localhost:8000/'
;
// Get a random task and input
const
task
=
getRandomTask
();
const
payload
=
`
${
task
.
taskName
}
&
${
task
.
input
}
`
;
// Define request headers
const
params
=
{
headers
:
{
'Content-Type'
:
'application/plain-text'
,
},
};
// Send POST request with random task and input
let
res
=
http
.
post
(
url
,
payload
,
params
);
// Check if the request succeeded (HTTP status 200)
check
(
res
,
{
'status was 200'
:
(
r
)
=>
r
.
status
===
200
,
});
// wait for 0.4 second between requests
sleep
(
0.4
);
}
K6TestsScripts/testSingleTaskResponse.js
0 → 100644
View file @
f80984c6
import
http
from
'k6/http'
;
import
{
check
}
from
'k6'
;
export
const
options
=
{
vus
:
1
,
// 1 virtual user
duration
:
'10s'
,
// test for 10 seconds
};
export
default
function
()
{
// Define The target Java server URL
const
url
=
'http://localhost:8000'
;
// Define the payload
const
payload
=
'TaskBubbleSort&1,5,3,4,2'
;
// Send the POST request
const
res
=
http
.
post
(
url
,
payload
);
// Log the response
//console.log('Response body: ' + res.body);
// Check the status and result
check
(
res
,
{
'status is 200'
:
(
r
)
=>
r
.
status
===
200
,
'result is correct'
:
(
r
)
=>
r
.
body
.
includes
(
'[1,2,3,4,5]'
),
// Expected output of sorting task
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment