generated from NASA-PDS/template-repo-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'automated-testing' of https://github.com/NASA-PDS/registry
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
This script is used to run a stress test Harvest | ||
To stress test Harvest with 25 simultaneous writes, run the following command: | ||
python harvest_stress_test.py --command "harvest_command_here" --runs 25 | ||
""" | ||
|
||
import argparse | ||
import concurrent.futures | ||
import subprocess | ||
|
||
|
||
def run_command(command): | ||
""" | ||
Runs the provided command as a subprocess and returns the result | ||
""" | ||
try: | ||
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
return f"Command: {command}\nStdout: {result.stdout}\nStderr: {result.stderr}" | ||
except Exception as e: | ||
return f"Command: {command}\nError: {str(e)}" | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Stress test Harvest with user-provided simultaneous runs.") | ||
parser.add_argument("command", help="The command to run") | ||
parser.add_argument("runs", type=int, help="The number of times to run Harvest simultaneously") | ||
|
||
args = parser.parse_args() | ||
|
||
command = args.command | ||
runs = args.runs | ||
|
||
# List of commands | ||
# use command.replace if you want to alter part of the command string for each process | ||
# commands = [command.replace("part to replace", "replace with this") for i in range(runs)] | ||
commands = [command for i in range(runs)] | ||
|
||
# Create a ThreadPoolExecutor with the desired number of workers | ||
with concurrent.futures.ThreadPoolExecutor(max_workers=runs) as executor: | ||
# Submit the commands for execution | ||
futures = [executor.submit(run_command, command) for command in commands] | ||
|
||
# Wait for all the commands to complete and retrieve the results | ||
results = [future.result() for future in concurrent.futures.as_completed(futures)] | ||
|
||
# Print the results | ||
for result in results: | ||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |