Skip to content

Commit

Permalink
Merge pull request #241 from NASA-PDS/harvest-multithreading-stress-test
Browse files Browse the repository at this point in the history
Merging Harvest Testing Code into General Automated Registry Testing Branch
  • Loading branch information
miguelp1986 authored Oct 27, 2023
2 parents 443919f + 0d03a90 commit 2ebe6d8
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [«unknown»](https://github.com/NASA-PDS/registry/tree/«unknown») (2023-10-24)

[Full Changelog](https://github.com/NASA-PDS/registry/compare/v1.3.0...«unknown»)

**Other closed issues:**

- Assist with DUM infra setup in MCP [\#238](https://github.com/NASA-PDS/registry/issues/238)

## [v1.3.0](https://github.com/NASA-PDS/registry/tree/v1.3.0) (2023-10-11)

[Full Changelog](https://github.com/NASA-PDS/registry/compare/v1.2.0...v1.3.0)
Expand Down
2 changes: 1 addition & 1 deletion docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ REG_API_APP_PROPERTIES_FILE=./default-config/application.properties
# --------------------------------------------------------------------

# Docker image of the Registry Loader
REG_LOADER_IMAGE=nasapds/registry-loader:0.4.0
REG_LOADER_IMAGE=nasapds/registry-loader:latest

# --------------------------------------------------------------------
# Registry Sweepers
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ services:
- ${POSTMAN_COLLECTION_FILE}:/postman/postman-collection.json
networks:
- pds
command: "run /postman/postman-collection.json --env-var baseUrl=${REG_API_URL} --reporters cli,testrail"
command: "run /postman/postman-collection.json --insecure --env-var baseUrl=${REG_API_URL} --env-var opensearchUrl=${ES_URL} --reporters cli,testrail"

# Executes Registry API integration test as a Postman collection with test data (after waiting for data to be loaded)
reg-api-integration-test-with-wait:
Expand Down
101 changes: 52 additions & 49 deletions docker/postman/postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@
"",
"var resp = pm.response.json();",
"",
"pm.test(\"C2723037 file size value does have brackets\", () => {",
"pm.test(\"C2723037 file size value doesn't have brackets\", () => {",
" pm.expect(resp[\"pds:File.pds:file_size\"]).to.equal(\"1365\"); ",
"});",
"",
Expand Down Expand Up @@ -855,58 +855,61 @@
},
{
"name": "opensearch requests",
"event": [
"item": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"C2723010 legacy_registry index exists\", () => {",
" pm.response.to.have.status(200);",
"});",
"",
"var resp = pm.response.json();",
"",
"pm.test(\"C2723010 more than 10000 synchronized products\", () => {",
" pm.expect(resp.hits.total.value).to.eql(10000); ",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "admin",
"type": "string"
},
"name": "legacy_registry",
"event": [
{
"key": "username",
"value": "admin",
"type": "string"
"listen": "test",
"script": {
"exec": [
"pm.test(\"C2723010 legacy_registry index exists\", () => {",
" pm.response.to.have.status(200);",
"});",
"",
"var resp = pm.response.json();",
"",
"pm.test(\"C2723010 more than 10000 synchronized products\", () => {",
" pm.expect(resp.hits.total.value).to.eql(10000); ",
"});",
""
],
"type": "text/javascript"
}
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "https://localhost:9200/legacy_registry/_search",
"protocol": "https",
"host": [
"localhost"
],
"port": "9200",
"path": [
"legacy_registry",
"_search"
]
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "admin",
"type": "string"
},
{
"key": "username",
"value": "admin",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{opensearchUrl}}/legacy_registry/_search",
"host": [
"{{opensearchUrl}}"
],
"path": [
"legacy_registry",
"_search"
]
}
},
"response": []
}
},
"response": []
]
}
],
"event": [
Expand Down Expand Up @@ -937,4 +940,4 @@
"value": "http://registry-api:8080"
}
]
}
}
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()
Loading

0 comments on commit 2ebe6d8

Please sign in to comment.