diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f0b8e3f58..d93f9afe9d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,14 +1,18 @@ name: "Tests" -on: [ pull_request ] +on: [pull_request] + +env: + COMPOSE_PROJECT_NAME: cache + jobs: - lint: - name: Tests + build: + name: Build (PHP ${{ matrix.php }}) runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - php-versions: ['8.3', '8.4', '8.5'] - + php: ['8.3', '8.4', '8.5'] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -17,12 +21,96 @@ jobs: - run: git checkout HEAD^2 - - name: Build - run: | - export PHP_VERSION=${{ matrix.php-versions }} - docker compose build - docker compose up -d - sleep 10 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Run Tests - run: docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml tests \ No newline at end of file + - name: Build tests image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.php-${{ matrix.php }} + tags: cache-tests:${{ matrix.php }} + cache-from: type=gha,scope=php-${{ matrix.php }} + cache-to: type=gha,mode=max,scope=php-${{ matrix.php }} + outputs: type=docker,dest=/tmp/cache-tests-${{ matrix.php }}.tar + + - name: Cache tests image + uses: actions/cache@v4 + with: + key: cache-tests-${{ matrix.php }}-${{ github.event.pull_request.head.sha }} + path: /tmp/cache-tests-${{ matrix.php }}.tar + + unit: + name: Unit (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + needs: build + strategy: + fail-fast: false + matrix: + php: ['8.3', '8.4', '8.5'] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Restore tests image + uses: actions/cache@v4 + with: + key: cache-tests-${{ matrix.php }}-${{ github.event.pull_request.head.sha }} + path: /tmp/cache-tests-${{ matrix.php }}.tar + fail-on-cache-miss: true + + - name: Start container + run: | + docker load --input /tmp/cache-tests-${{ matrix.php }}.tar + PHP_VERSION=${{ matrix.php }} docker compose up -d --no-deps --wait --wait-timeout 180 tests + + - name: Run unit tests + run: docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite unit + + adapter: + name: ${{ matrix.adapter.name }} (PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + needs: build + strategy: + fail-fast: false + matrix: + php: ['8.3', '8.4', '8.5'] + adapter: + - { name: Memory, suite: memory, services: '', wait: 0 } + - { name: None, suite: none, services: '', wait: 0 } + - { name: Filesystem, suite: filesystem, services: '', wait: 0 } + - { name: Pool, suite: pool, services: '', wait: 0 } + - { name: CircuitBreaker, suite: circuitbreaker, services: '', wait: 0 } + - { name: Telemetry, suite: telemetry, services: '', wait: 0 } + - { name: Memcached, suite: memcached, services: 'memcached', wait: 3 } + - { name: Hazelcast, suite: hazelcast, services: 'hazelcast', wait: 30 } + - { name: Sharding, suite: sharding, services: 'shardA shardB shardC', wait: 0 } + - { name: Redis, suite: redis, services: 'redis', wait: 0 } + - { name: RedisCluster, suite: redis-cluster, services: 'redis-cluster', wait: 0 } + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Restore tests image + uses: actions/cache@v4 + with: + key: cache-tests-${{ matrix.php }}-${{ github.event.pull_request.head.sha }} + path: /tmp/cache-tests-${{ matrix.php }}.tar + fail-on-cache-miss: true + + - name: Start services + run: | + docker load --input /tmp/cache-tests-${{ matrix.php }}.tar + PHP_VERSION=${{ matrix.php }} docker compose up -d --no-deps --wait --wait-timeout 180 tests ${{ matrix.adapter.services }} + if [ "${{ matrix.adapter.wait }}" -gt 0 ]; then sleep ${{ matrix.adapter.wait }}; fi + + - name: Run ${{ matrix.adapter.name }} tests + run: docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite ${{ matrix.adapter.suite }} diff --git a/docker-compose.yml b/docker-compose.yml index 94524c72a7..571b74bbd8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,16 @@ +name: cache + services: tests: container_name: tests + image: cache-tests:${PHP_VERSION:-8.4} build: context: . dockerfile: Dockerfile.php-${PHP_VERSION:-8.4} networks: - database volumes: - - ./phpunit.xml:/usr/code/phpunit.xml + - ./phpunit.xml:/usr/src/code/phpunit.xml - ./src:/usr/src/code/src - ./tests:/usr/src/code/tests - /var/run/docker.sock:/var/run/docker.sock @@ -23,6 +26,11 @@ services: redis: image: redis:6.0-alpine container_name: cache-redis + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + timeout: 3s + retries: 20 networks: - database @@ -32,6 +40,12 @@ services: hostname: redis-cluster environment: - IP=redis-cluster + healthcheck: + test: ["CMD-SHELL", "redis-cli -p 7000 cluster info | grep -q cluster_state:ok"] + interval: 3s + timeout: 5s + retries: 30 + start_period: 10s networks: - database @@ -41,31 +55,46 @@ services: HZ_NETWORK_MEMCACHEPROTOCOL_ENABLED: "true" container_name: hazelcast networks: - - database + - database memcached: image: memcached:1.6.17-alpine container_name: memcached networks: - database - + shardA: image: redis:6.0-alpine container_name: shardA + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + timeout: 3s + retries: 20 networks: - database - + shardB: image: redis:6.0-alpine container_name: shardB + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + timeout: 3s + retries: 20 networks: - - database - + - database + shardC: image: redis:6.0-alpine container_name: shardC + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + timeout: 3s + retries: 20 networks: - database networks: - database: \ No newline at end of file + database: diff --git a/phpunit.xml b/phpunit.xml index 1003a37b1f..c9029ccf90 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -12,8 +12,39 @@ ./tests/Cache/Unit - - ./tests/Cache/E2E + + ./tests/Cache/E2E/MemoryTest.php + + + ./tests/Cache/E2E/NoneTest.php + + + ./tests/Cache/E2E/FilesystemTest.php + + + ./tests/Cache/E2E/PoolTest.php + + + ./tests/Cache/E2E/CircuitBreakerTest.php + + + ./tests/Cache/E2E/TelemetryTest.php + + + ./tests/Cache/E2E/MemcachedTest.php + + + ./tests/Cache/E2E/HazelcastTest.php + + + ./tests/Cache/E2E/ShardingTest.php + + + ./tests/Cache/E2E/Redis + ./tests/Cache/E2E/Redis/RedisClusterTest.php + + + ./tests/Cache/E2E/Redis/RedisClusterTest.php