fix kafka consumer configuration #3094
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| pull_request: | |
| defaults: | |
| run: | |
| shell: bash | |
| concurrency: | |
| group: split-tests-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }} | |
| cancel-in-progress: true | |
| jobs: | |
| tests: | |
| name: Split Testing | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| include: | |
| - php-version: '8.2' | |
| - php-version: '8.4' | |
| - php-version: '8.2' | |
| stability: prefer-lowest | |
| services: | |
| kafka: | |
| image: apache/kafka:3.9.0 | |
| options: >- | |
| --env KAFKA_NODE_ID=0 | |
| --env KAFKA_PROCESS_ROLES=broker,controller | |
| --env [email protected]:9093 | |
| --env KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER | |
| --env KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://:9093 | |
| --env KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 | |
| --env KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT | |
| --env KAFKA_AUTO_CREATE_TOPICS_ENABLE=true | |
| --env KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 | |
| --env KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 | |
| --env KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 | |
| --env KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 | |
| ports: | |
| - 9092:9092 | |
| rabbitmq: | |
| image: rabbitmq:3.11-management-alpine | |
| env: | |
| RABBITMQ_DEFAULT_USER: guest | |
| RABBITMQ_DEFAULT_PASS: guest | |
| ports: | |
| - 5672:5672 | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: "secret" | |
| MYSQL_USER: "ecotone" | |
| MYSQL_PASSWORD: "secret" | |
| MYSQL_DATABASE: "ecotone" | |
| DB_PORT: 3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping" | |
| --health-interval=10s | |
| --health-timeout=10s | |
| --health-retries=5 | |
| ports: | |
| - 3306:3306 | |
| postgres: | |
| image: simplycodedsoftware/postgres:16.1 | |
| env: | |
| POSTGRES_USER: ecotone | |
| POSTGRES_PASSWORD: secret | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| localstack: | |
| image: localstack/localstack:3.0.0 | |
| env: | |
| SERVICES: 'sqs,sns' | |
| ports: | |
| - "4566:4566" | |
| - "4510-4559:4510-4559" | |
| redis: | |
| image: redis:7-alpine | |
| ports: | |
| - '6379:6379' | |
| env: | |
| RABBIT_HOST: amqp://127.0.0.1:5672 | |
| SQS_DSN: sqs:?key=key&secret=secret®ion=us-east-1&endpoint=http://127.0.0.1:4566&version=latest | |
| REDIS_DSN: redis://127.0.0.1:6379 | |
| KAFKA_DSN: 127.0.0.1:9092 | |
| COMPOSER_ROOT_VERSION: 'dev-main' | |
| COMPOSER_PROCESS_TIMEOUT: 3600 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set Up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| extensions: grpc, rdkafka | |
| coverage: none | |
| - name: Install OpenSSH (For Kafka) | |
| run: sudo apt-get update && sudo apt-get install -y --no-install-recommends openssh-client | |
| - name: Install DB clients | |
| run: sudo apt-get update && sudo apt-get install -y --no-install-recommends postgresql-client mysql-client | |
| - name: Wait for Kafka to be ready | |
| run: | | |
| echo "Waiting for Kafka to start..." | |
| for i in {1..30}; do | |
| if timeout 5 bash -c 'cat < /dev/null > /dev/tcp/127.0.0.1/9092' 2>/dev/null; then | |
| echo "Kafka is ready!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i: Kafka not ready yet, waiting 2 seconds..." | |
| sleep 2 | |
| done | |
| echo "Kafka failed to start within 60 seconds" | |
| exit 1 | |
| - name: Enable merge-plugin | |
| run: composer global config --no-interaction allow-plugins.wikimedia/composer-merge-plugin true && composer global require wikimedia/composer-merge-plugin | |
| - name: Run tests | |
| run: | | |
| COMPONENTS=$(find packages -maxdepth 2 -type f -name phpunit.xml.dist | xargs -I{} dirname {}) | |
| RUN_TESTS="composer tests:ci" | |
| if [ "${{ matrix.stability }}" = "prefer-lowest" ]; then | |
| COMPOSER_UP="composer update --${{ matrix.stability }}" | |
| else | |
| COMPOSER_UP="composer update" | |
| fi | |
| _run_tests() { | |
| local ok=0 | |
| local title="$1" | |
| local start=$(date -u +%s) | |
| OUTPUT=$(bash -xc "$2" 2>&1) || ok=$? | |
| local end=$(date -u +%s) | |
| if [[ $ok -ne 0 ]]; then | |
| printf "\n%-70s%10s\n" "$title" $(($end-$start))s | |
| echo "$OUTPUT" | |
| echo "Job exited with: $ok" | |
| echo -e "\n::error::KO $title\n" | |
| else | |
| printf "::group::%-68s%10s\n" "$title" $(($end-$start))s | |
| echo "$OUTPUT" | |
| echo -e "\n\e[32mOK\e[0m $title\n\n::endgroup::" | |
| fi | |
| return $ok | |
| } | |
| _run_component_tests() { | |
| local db_host="127.0.0.1" | |
| local dir="$1" | |
| local compose_up_cmd="$2" | |
| local run_tests_cmd="$3" | |
| local overall_exit_code=0 | |
| # Install dependencies and determine if MySQL pass is needed (direct or transitive doctrine/dbal) | |
| if ! _run_tests "Install composer dependencies ($dir)" "cd '${dir}' && ${compose_up_cmd}"; then | |
| overall_exit_code=1 | |
| fi | |
| local has_dbal=0 | |
| if bash -c "cd '${dir}' && composer show doctrine/dbal > /dev/null 2>&1"; then | |
| has_dbal=1 | |
| fi | |
| if [ "$has_dbal" -eq 1 ]; then | |
| # Derive unique DB names per component execution to avoid cross-test conflicts | |
| local slug=$(echo "$dir" | tr '/.-' '___' | tr '[:upper:]' '[:lower:]') | |
| local db_name | |
| # Run Postgres pass | |
| db_name="ecotone_${slug}_pg" | |
| if ! _run_tests "$dir (Postgres)" "\ | |
| psql 'postgresql://ecotone:secret@${db_host}:5432/postgres' -v ON_ERROR_STOP=1 -c 'CREATE DATABASE ${db_name} OWNER ecotone' && \ | |
| mysql -h '${db_host}' -uroot -psecret -e \"CREATE DATABASE ${db_name}; GRANT ALL PRIVILEGES ON ${db_name}.* TO 'ecotone'@'%'; FLUSH PRIVILEGES;\" && \ | |
| cd '${dir}' && \ | |
| DATABASE_DSN='pgsql://ecotone:secret@${db_host}:5432/${db_name}?serverVersion=16' \ | |
| SECONDARY_DATABASE_DSN='mysql://ecotone:secret@${db_host}:3306/${db_name}?serverVersion=8' \ | |
| ${run_tests_cmd}"; then | |
| overall_exit_code=1 | |
| fi | |
| # Run MySQL pass | |
| db_name="ecotone_${slug}_mysql" | |
| if ! _run_tests "$dir (MySQL)" "\ | |
| psql 'postgresql://ecotone:secret@${db_host}:5432/postgres' -v ON_ERROR_STOP=1 -c 'CREATE DATABASE ${db_name} OWNER ecotone' && \ | |
| mysql -h '${db_host}' -uroot -psecret -e \"CREATE DATABASE ${db_name}; GRANT ALL PRIVILEGES ON ${db_name}.* TO 'ecotone'@'%'; FLUSH PRIVILEGES;\" && \ | |
| cd '${dir}' && \ | |
| DATABASE_DSN='mysql://ecotone:secret@${db_host}:3306/${db_name}?serverVersion=8' \ | |
| SECONDARY_DATABASE_DSN='pgsql://ecotone:secret@${db_host}:5432/${db_name}?serverVersion=16' \ | |
| ${run_tests_cmd}"; then | |
| overall_exit_code=1 | |
| fi | |
| else | |
| # No DB dependency: run tests with no DB env vars | |
| if ! _run_tests "$dir" "cd '${dir}' && ${run_tests_cmd}"; then | |
| overall_exit_code=1 | |
| fi | |
| fi | |
| return $overall_exit_code | |
| } | |
| export -f _run_tests _run_component_tests | |
| # Run tests in parallel and collect exit codes | |
| echo "$COMPONENTS" | xargs -n1 | parallel -j +3 "_run_component_tests {} '$COMPOSER_UP' '$RUN_TESTS'" |