Skip to content

Commit

Permalink
feat: update AWS deployment and unit tests
Browse files Browse the repository at this point in the history
docs: readme.md for unit tests
  • Loading branch information
albertkun committed Nov 10, 2023
1 parent dd70896 commit 4545e7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/dev-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ jobs:
- name: Push Updated Docker Image on Lightsail Dev
if: steps.changed-files.outputs.any_changed == 'true'
run: |
aws lightsail create-container-service-deployment \
--service-name dev-metro-api-v2 \
aws lightsail create-container-service-deployment
--service-name dev-metro-api-v2
--containers '{"memcached": {"image": "memcached:latest", "environment": {}, "ports": {"11211": "TCP"}}, "data-loading-service": {"image":"lacmta/metro-api-v2:data-loading-service", "environment": {"FTP_SERVER": "${{secrets.FTP_SERVER}}", "FTP_USERNAME": "${{secrets.FTP_USERNAME}}", "FTP_PASS": "${{secrets.FTP_PASS}}", "SWIFTLY_AUTH_KEY_BUS": "${{secrets.SWIFTLY_AUTH_KEY_BUS}}", "SWIFTLY_AUTH_KEY_RAIL": "${{secrets.SWIFTLY_AUTH_KEY_RAIL}}", "AWS_ACCESS_KEY_ID": "${{secrets.AWS_ACCESS_KEY_ID}}", "ACCESS_SECRET_KEY": "${{secrets.ACCESS_SECRET_KEY}}", "SWIFTLY_AUTH_KEY": "${{secrets.SWIFTLY_AUTH_KEY}}", "API_DB_URI": "${{secrets.API_DB_URI}}", "HASH_KEY": "${{secrets.HASH_KEY}}", "HASHING_ALGORITHM": "${{secrets.HASHING_ALGORITHM}}", "LOGZIO_TOKEN": "${{secrets.LOGZIO_TOKEN}}", "LOGZIO_URL": "${{secrets.LOGZIO_URL}}", "RUNNING_ENV": "dev"}}, "fastapi": {"image":"lacmta/metro-api-v2:fastapi", "environment": {"FTP_SERVER": "${{secrets.FTP_SERVER}}", "FTP_USERNAME": "${{secrets.FTP_USERNAME}}", "FTP_PASS": "${{secrets.FTP_PASS}}", "SWIFTLY_AUTH_KEY_BUS": "${{secrets.SWIFTLY_AUTH_KEY_BUS}}", "SWIFTLY_AUTH_KEY_RAIL": "${{secrets.SWIFTLY_AUTH_KEY_RAIL}}", "AWS_ACCESS_KEY_ID": "${{secrets.AWS_ACCESS_KEY_ID}}", "ACCESS_SECRET_KEY": "${{secrets.ACCESS_SECRET_KEY}}", "SWIFTLY_AUTH_KEY": "${{secrets.SWIFTLY_AUTH_KEY}}", "API_DB_URI": "${{secrets.API_DB_URI}}", "HASH_KEY": "${{secrets.HASH_KEY}}", "HASHING_ALGORITHM": "${{secrets.HASHING_ALGORITHM}}", "LOGZIO_TOKEN": "${{secrets.LOGZIO_TOKEN}}", "LOGZIO_URL": "https://listener.logz.io:8071", "RUNNING_ENV": "dev", "MEMCACHED_HOST": "dev-metro-api-v2.service.local","MEMCACHED_PORT":"11211"}, "ports": {"80": "HTTP"}}}' --public-endpoint '{"containerName": "fastapi","containerPort": 80,"healthCheck":{ "healthyThreshold": 2,"unhealthyThreshold": 2,"timeoutSeconds": 2,"intervalSeconds": 5,"path": "/","successCodes": "200-499"}}'
deploy-documentation:
runs-on: ubuntu-latest
name: Deploy Documentation to GitHub Pages
Expand All @@ -108,7 +107,7 @@ jobs:
run: yarn build
- name: Deploy Documentation to GitHub Pages
if: steps.changed-documentation.outputs.any_changed == 'true'
uses: peaceiris/actions-gh-pages@v4
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.METRO_GITHUB_TOKEN }}
publish_dir: ./documentation/build
Expand Down
33 changes: 21 additions & 12 deletions fastapi/tests/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Project Name
# Metro FastAPI Unit Tests

## Setup

Expand All @@ -8,18 +8,34 @@ Install the required Python packages:
pip install -r requirements.txt
```

## Running Tests
## Running all tests

This project uses `pytest` for unit testing. To run the tests, use the following command:
This project uses `pytest` for unit testing. To run all the tests, use the following command:

```bash
pytest tests/test_main.py
```

This command will run all test cases in the test_main.py file.

### Load Testing
This project uses `locust` for load testing.
### Logs

The tests will generate a log with naming in the following format:

`test_log_YEARMONTHDAY_TIME.txt`

That has details on the number of tests failed.

## Endpoint Testing
We use `pytest` to test the endpoints and it can be run using

`python test_endpoints.py`


## Load Testing
We use `locust` for load testing.

> Note: Ideally, you should run on a different machine that has access to the server running our fastapi application.
To run the load tests, use the following command:
```bash
Expand All @@ -29,10 +45,3 @@ locust -f test_load.py -u 2000 -r 100

This command will start a swarm of 2000 users, with a hatch rate of 100 users per second, using the Locust file in your tests directory.

### Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

### License
This project is licensed under the MIT License - see the LICENSE.md file for details

```
2 changes: 1 addition & 1 deletion fastapi/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def run_tests():
log_file_name = f'test_log_{timestamp}.txt'
with open(log_file_name, 'w') as f:
print("Running unit tests...", file=f)
result = subprocess.run(["pytest", "-v", "test_main.py"], stdout=f, text=True)
result = subprocess.run(["pytest", "-v", "test_endpoints.py"], stdout=f, text=True)
if result.returncode == 0:
print("Unit tests check has passed", file=f)
else:
Expand Down
File renamed without changes.

0 comments on commit 4545e7f

Please sign in to comment.