Skip to content

dimagi/rep-test-srv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repeater Test Service

This is a small HTTP response service, created for testing CommCare HQ Data Forwarding, a.k.a. Repeaters.

It supports the following features:

  • GET or POST to a root endpoint, e.g. https://api.example.com/: Returns a 200 response.
  • Rate-limit requests per second: For example, POST https://api.example.com/rps/5/ returns a 200 response, or a 429 response if more than 5 requests are received per second from the same IP address.
  • Rate-limit requests per minute: Like rate-limit requests per second. e.g. POST https://api.example.com/rpm/300/.
  • Return a given status code: e.g. POST https://api.example.com/status/418/ will return status code 418.
  • Return a given status code with a given possibility: e.g. POST https://api.example.com/status/418/percent/50/ will return status code 418 on 50% of requests, and 200 the rest of the time.

For everything else, you probably want httpbin.

The Repeater Test Service is built using Quart, the asyncio web microframework based on Flask.

Requirements

The Repeater Test Service requires Redis, and is tested using Python 3.12, although it probably works with other versions.

Installing a development environment

  1. Clone this repository.

  2. Create a virtual environment and activate it:

    $ python3.12 -m venv venv
    $ source venv/bin/activate
  3. Install the dependencies, including testing dependencies:

    $ pip install -e '.[test]'
  4. Set the QUART_REDIS_URI environment variable. e.g.

    $ export QUART_REDIS_URI='redis://localhost:6379/0'

    The use of .env is supported. e.g.

    $ echo "QUART_REDIS_URI = 'redis://localhost:6379/0'" > .env

Running

To run the service, use the following command:

$ export QUART_APP=http_resp:app
$ quart run

Testing

To run the tests, use the following command:

$ export QUART_APP=http_resp:app
$ pytest

VPS Deployment

To deploy on a virtual private server, clone this repository into /opt/rep-test-srv/.

Check the assumption made in run.sh regarding the external network device name.

Create a symlink to rep-test-srv.service in /etc/systemd/system/:

$ cd /etc/systemd/system/
$ sudo ln -s /opt/rep-test-srv/rep-test-srv.service

Reload systemd, and enable the service:

$ sudo systemctl daemon-reload
$ sudo systemctl enable rep-test-srv.service

About

A CommCare HQ Repeater Test Service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published