diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 44ff652..3e059ed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,23 +12,21 @@ jobs: name: Integration Tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run integration tests - Redis host - run: | - docker-compose -f ./int/docker-compose.yml run tests - - name: Run integration tests - Redis cluster - run: | - docker network create --subnet=172.28.0.0/24 test_network - export REDIS_PASSWORD=test1234 - export NETWORK_NAME=test_network - docker-compose -f ./int/docker-compose.yml down - docker-compose -f ./int/docker-compose.cluster.yml run tests - - name: Print logs on failure - if: failure() - run: | - docker-compose -f ./int/docker-compose.yml logs - docker-compose -f ./int/docker-compose.cluster.yml logs - - name: Clean up integration tests - if: always() - run: | - docker-compose -f ./int/docker-compose.cluster.yml down + - uses: actions/checkout@v2 + - name: Run integration tests - Redis cluster + run: | + docker network create --subnet=172.28.0.0/24 test_network + export REDIS_PASSWORD=test1234 + export NETWORK_NAME=test_network + docker-compose -f ./int/docker-compose.yml run tests-cluster + - name: Run integration tests - Redis host + run: | + docker-compose -f ./int/docker-compose.yml run tests-host + - name: Print logs on failure + if: failure() + run: | + docker-compose -f ./int/docker-compose.yml logs + - name: Clean up integration tests + if: always() + run: | + docker-compose -f ./int/docker-compose.yml down diff --git a/README.md b/README.md index 2a9a411..d5973ab 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,7 @@ configuration options are defined as follows: ### Single redis host ```sh -$ docker-compose -f int/docker-compose.yml build -$ docker-compose -f int/docker-compose.yml run tests +$ docker-compose -f int/docker-compose.yml run tests-host ``` ### Redis cluster @@ -109,6 +108,5 @@ Cluster requires external docker network with specified subnet $ docker network create --subnet=172.28.0.0/24 `network_name` $ export REDIS_PASSWORD=" ... As specified in redis_cluster.conf ... " $ export NETWORK_NAME="`network_name`" -$ docker-compose -f int/docker-compose.cluster.yml build -$ docker-compose -f int/docker-compose.cluster.yml run tests +$ docker-compose -f int/docker-compose.yml run tests-cluster ``` diff --git a/acapy_cache_redis/v0_1/redis_base_cache.py b/acapy_cache_redis/v0_1/redis_base_cache.py index 944179c..005d20c 100644 --- a/acapy_cache_redis/v0_1/redis_base_cache.py +++ b/acapy_cache_redis/v0_1/redis_base_cache.py @@ -88,7 +88,7 @@ async def check_for_redis_cluster(self): # host then it will return None as it doesn't exists. Otherwise, # it will raise a MOVED error. fake_test_key = f"test_key_{str(uuid4())}" - await self.redis.set(fake_test_key, b"") + await self.redis.set(fake_test_key, b"", ex=1) except aioredis.exceptions.ResponseError as err: if "MOVED" in str(err): self.redis = self.root_profile.inject_or(RedisCluster) diff --git a/int/docker-compose.cluster.yml b/int/docker-compose.cluster.yml deleted file mode 100644 index 3e753af..0000000 --- a/int/docker-compose.cluster.yml +++ /dev/null @@ -1,148 +0,0 @@ -version: "3" -services: - agent: - image: acapy-cache-redis - build: - context: ../ - dockerfile: ./docker/Dockerfile - depends_on: - - redis-cluster - # volumes: - # - ./acapy-endpoint.sh:/acapy-endpoint.sh:ro,z - # - ./acapy_cache_redis:/home/indy/acapy_cache_redis:ro,z - # - ./docker/default_cluster.yml:/home/indy/default.yml:ro,z - command: > - start -it http 0.0.0.0 3000 - -ot http - -e http://agent:3000 - --admin 0.0.0.0 3001 --admin-insecure-mode - --no-ledger - --plugin acapy_cache_redis.v0_1 - --plugin-config-value redis_cache.connection="redis://default:test1234@172.28.0.103:6379" - --log-level debug - networks: - - acapy_default - redis-cluster: - image: redis:latest - container_name: cluster - command: redis-cli --cluster create 172.28.0.101:6377 172.28.0.102:6378 172.28.0.103:6379 172.28.0.104:6380 172.28.0.105:6381 172.28.0.106:6382 --cluster-replicas 1 --cluster-yes - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - networks: - acapy_default: - ipv4_address: 172.28.0.107 - depends_on: - - redis-node-1 - - redis-node-2 - - redis-node-3 - - redis-node-4 - - redis-node-5 - - redis-node-6 - redis-node-1: - image: redis:latest - container_name: node1 - command: [ "redis-server", "/conf/redis.conf", "--port 6377" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6377:6377 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.101 - redis-node-2: - image: redis:latest - container_name: node2 - command: [ "redis-server", "/conf/redis.conf", "--port 6378" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6378:6378 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.102 - redis-node-3: - image: redis:latest - container_name: node3 - command: [ "redis-server", "/conf/redis.conf", "--port 6379" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6379:6379 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.103 - redis-node-4: - image: redis:latest - container_name: node4 - command: [ "redis-server", "/conf/redis.conf", "--port 6380" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6380:6380 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.104 - redis-node-5: - image: redis:latest - container_name: node5 - command: [ "redis-server", "/conf/redis.conf", "--port 6381" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6381:6381 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.105 - redis-node-6: - image: redis:latest - container_name: node6 - command: [ "redis-server", "/conf/redis.conf", "--port 6382" ] - environment: - - REDISCLI_AUTH=${REDIS_PASSWORD} - ports: - - 6382:6382 - volumes: - - ../redis_cluster.conf:/conf/redis.conf - networks: - acapy_default: - ipv4_address: 172.28.0.106 - echo: - image: dbluhm/echo-agent:6c22a88 - ports: - - "3002:3002" - command: --host 0.0.0.0 --port 3002 --log-level debug - networks: - - acapy_default - tests: - container_name: juggernaut - build: - context: . - dockerfile: ./Dockerfile.cluster - environment: - - WAIT_BEFORE_HOSTS=3 - - WAIT_HOSTS=agent:3000,echo:3002,redis-node-3:6379 - - WAIT_HOSTS_TIMEOUT=60 - - WAIT_SLEEP_INTERVAL=1 - - WAIT_HOST_CONNECT_TIMEOUT=30 - - AGENT_ENDPOINT=http://agent:3000 - - ADMIN_ENDPOINT=http://agent:3001 - - ECHO_ENDPOINT=http://echo:3002 - depends_on: - - agent - - echo - networks: - - acapy_default -networks: - acapy_default: - external: true - name: ${NETWORK_NAME} diff --git a/int/docker-compose.yml b/int/docker-compose.yml index 0434b2f..be5501f 100644 --- a/int/docker-compose.yml +++ b/int/docker-compose.yml @@ -1,10 +1,152 @@ version: "3" services: - agent: + agent-cluster: image: acapy-cache-redis build: - context: ../ - dockerfile: ./docker/Dockerfile + context: ../ + dockerfile: ./docker/Dockerfile + depends_on: + - redis-cluster + # volumes: + # - ./acapy-endpoint.sh:/acapy-endpoint.sh:ro,z + # - ./acapy_cache_redis:/home/indy/acapy_cache_redis:ro,z + # - ./docker/default_cluster.yml:/home/indy/default.yml:ro,z + command: > + start -it http 0.0.0.0 3000 + -ot http + -e http://agent-cluster:3000 + --admin 0.0.0.0 3001 --admin-insecure-mode + --no-ledger + --plugin acapy_cache_redis.v0_1 + --plugin-config-value redis_cache.connection="redis://default:test1234@172.28.0.103:6382" + --log-level debug + networks: + - acapy_default + redis-cluster: + image: redis:latest + container_name: cluster + command: redis-cli --cluster create 172.28.0.101:6380 172.28.0.102:6381 172.28.0.103:6382 172.28.0.104:6383 172.28.0.105:6384 172.28.0.106:6385 --cluster-replicas 1 --cluster-yes + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + networks: + acapy_default: + ipv4_address: 172.28.0.107 + depends_on: + - redis-node-1 + - redis-node-2 + - redis-node-3 + - redis-node-4 + - redis-node-5 + - redis-node-6 + redis-node-1: + image: redis:latest + container_name: node1 + command: [ "redis-server", "/conf/redis.conf", "--port 6380" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6380:6380 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.101 + redis-node-2: + image: redis:latest + container_name: node2 + command: [ "redis-server", "/conf/redis.conf", "--port 6381" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6381:6381 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.102 + redis-node-3: + image: redis:latest + container_name: node3 + command: [ "redis-server", "/conf/redis.conf", "--port 6382" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6382:6382 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.103 + redis-node-4: + image: redis:latest + container_name: node4 + command: [ "redis-server", "/conf/redis.conf", "--port 6383" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6383:6383 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.104 + redis-node-5: + image: redis:latest + container_name: node5 + command: [ "redis-server", "/conf/redis.conf", "--port 6384" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6384:6384 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.105 + redis-node-6: + image: redis:latest + container_name: node6 + command: [ "redis-server", "/conf/redis.conf", "--port 6385" ] + environment: + - REDISCLI_AUTH=${REDIS_PASSWORD} + ports: + - 6385:6385 + volumes: + - ../redis_cluster.conf:/conf/redis.conf + networks: + acapy_default: + ipv4_address: 172.28.0.106 + echo-cluster: + image: dbluhm/echo-agent:6c22a88 + ports: + - "3002:3002" + command: --host 0.0.0.0 --port 3002 --log-level debug + networks: + - acapy_default + tests-cluster: + container_name: juggernaut + build: + context: . + dockerfile: ./Dockerfile.cluster + environment: + - WAIT_BEFORE_HOSTS=3 + - WAIT_HOSTS=agent-cluster:3000,echo-cluster:3002,redis-node-3:6382 + - WAIT_HOSTS_TIMEOUT=60 + - WAIT_SLEEP_INTERVAL=1 + - WAIT_HOST_CONNECT_TIMEOUT=30 + - AGENT_ENDPOINT=http://agent-cluster:3000 + - ADMIN_ENDPOINT=http://agent-cluster:3001 + - ECHO_ENDPOINT=http://echo-cluster:3002 + depends_on: + - agent-cluster + - echo-cluster + networks: + - acapy_default + agent-host: + image: acapy-cache-redis + build: + context: ../ + dockerfile: ./docker/Dockerfile depends_on: redis-host: condition: service_healthy @@ -13,47 +155,48 @@ services: # - ./acapy_cache_redis:/home/indy/acapy_cache_redis:ro,z # - ./docker/default.yml:/home/indy/default.yml:ro,z command: > - start -it http 0.0.0.0 3000 + start -it http 0.0.0.0 3003 -ot http - -e http://agent:3000 - --admin 0.0.0.0 3001 --admin-insecure-mode + -e http://agent-host:3003 + --admin 0.0.0.0 3004 --admin-insecure-mode --no-ledger --plugin acapy_cache_redis.v0_1 --plugin-config-value redis_cache.connection="redis://redis-host:6379/0" --log-level debug - redis-host: image: "redis:alpine" healthcheck: - test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ] ports: - - "6379:6379" + - "6379:6379" # volumes: # - ./redis-data:/var/lib/redis # - ./redis.conf:/etc/redis/redis.conf:ro,z environment: - - REDIS_REPLICATION_MODE=master - - echo: + - REDIS_REPLICATION_MODE=master + echo-host: image: dbluhm/echo-agent:6c22a88 ports: - - "3002:3002" - command: --host 0.0.0.0 --port 3002 --log-level debug - - tests: + - "3005:3005" + command: --host 0.0.0.0 --port 3005 --log-level debug + tests-host: container_name: juggernaut build: context: . dockerfile: ./Dockerfile environment: - - WAIT_BEFORE_HOSTS=3 - - WAIT_HOSTS=agent:3000,echo:3002 + - WAIT_BEFORE_HOSTS=10 + - WAIT_HOSTS=agent-host:3003,echo-host:3005,redis-host:6379 - WAIT_HOSTS_TIMEOUT=60 - WAIT_SLEEP_INTERVAL=1 - WAIT_HOST_CONNECT_TIMEOUT=30 - - AGENT_ENDPOINT=http://agent:3000 - - ADMIN_ENDPOINT=http://agent:3001 - - ECHO_ENDPOINT=http://echo:3002 + - AGENT_ENDPOINT=http://agent-host:3003 + - ADMIN_ENDPOINT=http://agent-host:3004 + - ECHO_ENDPOINT=http://echo-host:3005 depends_on: - - agent - - echo + - agent-host + - echo-host +networks: + acapy_default: + external: true + name: ${NETWORK_NAME} diff --git a/int/tests/cluster/conftest.py b/int/tests/cluster/conftest.py index 4db92a1..edb4c92 100644 --- a/int/tests/cluster/conftest.py +++ b/int/tests/cluster/conftest.py @@ -62,7 +62,7 @@ def backchannel(backchannel_endpoint): @pytest.fixture(scope="session") async def redis_cluster_client(): """Yield RedisCluster client.""" - redis = RedisCluster.from_url(url="redis://default:test1234@172.28.0.103:6379") + redis = RedisCluster.from_url(url="redis://default:test1234@172.28.0.103:6382") yield redis await redis.close() diff --git a/int/tests/host/conftest.py b/int/tests/host/conftest.py index 66aefdb..e27d2ec 100644 --- a/int/tests/host/conftest.py +++ b/int/tests/host/conftest.py @@ -62,7 +62,7 @@ def backchannel(backchannel_endpoint): @pytest.fixture(scope="session") async def redis_client(): """Yield aioredis client.""" - redis = aioredis.from_url("redis://redis-host/0") + redis = aioredis.from_url("redis://redis-host:6379/0") yield redis await redis.close()