mirror of
https://github.com/mCaptcha/cache.git
synced 2026-01-25 04:16:29 +00:00
integration tests and makefile
This commit is contained in:
69
.github/workflows/linux.yml
vendored
69
.github/workflows/linux.yml
vendored
@@ -37,25 +37,43 @@ jobs:
|
||||
profile: minimal
|
||||
override: false
|
||||
|
||||
- name: build
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --all --bins --examples --tests
|
||||
- name: install dependencies
|
||||
run: make dev-env
|
||||
|
||||
- name: tests
|
||||
uses: actions-rs/cargo@v1
|
||||
timeout-minutes: 40
|
||||
with:
|
||||
command: test
|
||||
args: --all --all-features --no-fail-fast
|
||||
- name: build docker image
|
||||
run: make docker-build
|
||||
|
||||
- name: Generate coverage file
|
||||
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||
uses: actions-rs/tarpaulin@v0.1
|
||||
with:
|
||||
version: '0.15.0'
|
||||
args: '-t 1200 --all-features'
|
||||
- name: start docker container
|
||||
run: make docker-start
|
||||
|
||||
- name: run tests
|
||||
run: make test
|
||||
|
||||
- name: generate coverage
|
||||
run: make xml-test-coverage
|
||||
|
||||
- name: stop docker container
|
||||
run: make docker-stop
|
||||
|
||||
# - name: build
|
||||
# uses: actions-rs/cargo@v1
|
||||
# with:
|
||||
# command: build
|
||||
# args: --all --bins --examples --tests
|
||||
#
|
||||
# - name: tests
|
||||
# uses: actions-rs/cargo@v1
|
||||
# timeout-minutes: 40
|
||||
# with:
|
||||
# command: test
|
||||
# args: --all --all-features --no-fail-fast
|
||||
#
|
||||
# - name: Generate coverage file
|
||||
# if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||
# uses: actions-rs/tarpaulin@v0.1
|
||||
# with:
|
||||
# version: '0.15.0'
|
||||
# args: '-t 1200 --all-features'
|
||||
|
||||
- name: Upload to Codecov
|
||||
if: matrix.version == 'stable' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')
|
||||
@@ -63,15 +81,20 @@ jobs:
|
||||
with:
|
||||
file: cobertura.xml
|
||||
|
||||
|
||||
- name: generate documentation
|
||||
if: matrix.version == 'stable' && (github.repository == 'realaravinth/damn-vuln-blockchain')
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: doc
|
||||
args: --no-deps --workspace --all-features
|
||||
if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
|
||||
run: make docs
|
||||
|
||||
# - name: generate documentation
|
||||
# if: matrix.version == 'stable' && (github.repository == 'realaravinth/damn-vuln-blockchain')
|
||||
# uses: actions-rs/cargo@v1
|
||||
# with:
|
||||
# command: doc
|
||||
# args: --no-deps --workspace --all-features
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
if: matrix.version == 'stable' && (github.repository == 'realaravinth/damn-vuln-blockchain')
|
||||
if: matrix.version == 'stable' && (github.repository == 'mcaptcha/cache')
|
||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
48
Makefile
Normal file
48
Makefile
Normal file
@@ -0,0 +1,48 @@
|
||||
default:
|
||||
cargo build --release
|
||||
|
||||
test:
|
||||
cargo test --all --all-features --no-fail-fast
|
||||
./tests/test.py
|
||||
|
||||
docker-build:
|
||||
docker build -t mcaptcha/cache:0.1.1-alpha .
|
||||
|
||||
docker-stop:
|
||||
docker stop mcaptcha_cache_test || true
|
||||
docker rm mcaptcha_cache_test
|
||||
|
||||
docker-run:
|
||||
docker run --detach --name=mcaptcha_cache_test \
|
||||
--publish 6379:6379 \
|
||||
mcaptcha/cache:0.1.1-alpha
|
||||
|
||||
dev-env:
|
||||
./scripts/setup.sh
|
||||
|
||||
docs:
|
||||
cargo doc --no-deps --workspace --all-features
|
||||
|
||||
xml-test-coverage:
|
||||
cargo tarpaulin -t 1200 --out Xml --all --all-features --no-fail-fast
|
||||
|
||||
coverage:
|
||||
cargo tarpaulin -t 1200 --out Html --all --all-features --no-fail-fast
|
||||
dev:
|
||||
cargo build
|
||||
|
||||
clean:
|
||||
cargo clean
|
||||
|
||||
help:
|
||||
@echo ' run - run developer instance'
|
||||
@echo ' test - run unit and integration tests'
|
||||
@echo ' docker-build - build docker image'
|
||||
@echo ' docker-run - run docker container'
|
||||
@echo ' docker-stop - stop docker container'
|
||||
@echo ' dev-env - setup dev env'
|
||||
@echo ' docs - build documentation'
|
||||
@echo ' clean - drop builds and environments'
|
||||
@echo ' coverage - build test coverage in HTML format'
|
||||
@echo ' xml-coverage - build test coverage in XML for upload to codecov'
|
||||
@echo ''
|
||||
4
scripts/setup.sh
Executable file
4
scripts/setup.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
# set up for tests
|
||||
pip install --requirement ./tests/requirements.txt
|
||||
1
tests/requirements.txt
Normal file
1
tests/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
redis==3.5.3
|
||||
70
tests/test.py
Executable file
70
tests/test.py
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
|
||||
from redis.client import Redis
|
||||
from redis import BlockingConnectionPool
|
||||
|
||||
REDIS_URL = "redis://localhost:6350"
|
||||
|
||||
COMMANDS = {
|
||||
"COUNT" : "mcaptcha_cache.count",
|
||||
"GET" : "mcaptcha_cache.get",
|
||||
}
|
||||
|
||||
|
||||
KEY = "testing_module"
|
||||
TIME = 20
|
||||
|
||||
def connect():
|
||||
r = Redis(connection_pool=BlockingConnectionPool(max_connections=2))
|
||||
r.from_url(REDIS_URL)
|
||||
return r
|
||||
|
||||
r = connect()
|
||||
|
||||
def ping():
|
||||
resp = r.ping()
|
||||
assert resp is True
|
||||
|
||||
def incr(key, time):
|
||||
r.execute_command(COMMANDS["COUNT"], key, time)
|
||||
|
||||
def get_count(key):
|
||||
try:
|
||||
count = r.execute_command(COMMANDS["GET"], key)
|
||||
return int(count)
|
||||
except:
|
||||
return 0
|
||||
|
||||
def race(count):
|
||||
for _ in range(count):
|
||||
incr(KEY, TIME)
|
||||
|
||||
def assert_count(expect):
|
||||
count = get_count(KEY)
|
||||
assert count == expect
|
||||
|
||||
def main():
|
||||
# check connectivity
|
||||
ping()
|
||||
# get initial count(residual)
|
||||
initial_count = get_count(KEY)
|
||||
# incriment
|
||||
incr(KEY, TIME)
|
||||
assert_count(initial_count + 1)
|
||||
# wait till expiry
|
||||
sleep(TIME + 4)
|
||||
assert_count(initial_count)
|
||||
# increment by 200
|
||||
race_num = 200
|
||||
race(race_num)
|
||||
assert_count(initial_count + race_num)
|
||||
# wait till expiry
|
||||
sleep(TIME + 4)
|
||||
assert_count(initial_count)
|
||||
print("All good")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user