Skip to content

Commit

Permalink
Merge branch 'automated-testing' of https://github.com/NASA-PDS/registry
Browse files Browse the repository at this point in the history
 into automated-testing

Pull in merge automated-testing code locally
  • Loading branch information
miguelp1986 committed Oct 27, 2023
2 parents dc7383b + 2ebe6d8 commit 6e09882
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docker/scripts/harvest_stress_test.py
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()

0 comments on commit 6e09882

Please sign in to comment.