-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18e91c9
commit 6526a01
Showing
11 changed files
with
619 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useState } from "react"; | ||
import axios from "axios"; | ||
|
||
const LoadTest = () => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [responses, setResponses] = useState([]); | ||
|
||
// Send a GET request to the base API | ||
const sendRequest = async () => { | ||
try { | ||
const response = await axios.get("http://localhost:8000"); // Your base API | ||
setResponses((prev) => [...prev, response.data]); | ||
} catch (error) { | ||
console.error("Request failed:", error); | ||
} | ||
}; | ||
|
||
// Start the load test by sending 50 requests per second | ||
const startLoadTest = () => { | ||
setIsLoading(true); | ||
|
||
// Interval to send requests at 50 requests per second | ||
const interval = setInterval(() => { | ||
sendRequest(); | ||
}, 20); // Every 20ms to simulate 50 requests per second | ||
|
||
// Stop after 10 seconds | ||
setTimeout(() => { | ||
clearInterval(interval); | ||
setIsLoading(false); | ||
}, 10000); // Run the test for 10 seconds | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>API Load Test</h2> | ||
<button onClick={startLoadTest} disabled={isLoading}> | ||
{isLoading ? "Testing..." : "Start Load Test"} | ||
</button> | ||
|
||
<h3>Responses</h3> | ||
<pre>{JSON.stringify(responses, null, 2)}</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoadTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
const ButtonLoader = ( ) => { | ||
|
||
return ( | ||
<div className="flex justify-center items-center "> | ||
<div | ||
className={`border-4 h-6 w-6 border-t-orange-700 bg-orange-500 border-orange-500 border-solid rounded-full`} | ||
style={{ | ||
animation: "spin 1s linear infinite", | ||
}} | ||
></div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ButtonLoader; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const Notification = ({ message, type, onClose, className = "", icon = null }) => { | ||
const [visible, setVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
setVisible(true); | ||
|
||
const timer = setTimeout(() => { | ||
setVisible(false); | ||
setTimeout(onClose, 500); | ||
}, 3000); | ||
|
||
return () => clearTimeout(timer); | ||
}, [onClose]); | ||
|
||
return ( | ||
<div | ||
className={`fixed bottom-5 right-5 flex items-center gap-3 p-4 rounded-md text-white text-sm shadow-lg transition-all duration-500 transform ${ | ||
visible ? "translate-y-0 opacity-100" : "translate-y-10 opacity-0" | ||
} ${type === "success" ? "bg-green-500" : "bg-red-500"} ${className}`} | ||
> | ||
{icon && <img src={icon} alt="icon" className="w-6 h-6" />} | ||
<span>{message}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Notification; |
Oops, something went wrong.