LoginSignup
0
0

ghaにおけるrspecで発生するActiveRecord::ConnectionNotEstablished: MySQL client is not connected への対処案(動作未確認)

Last updated at Posted at 2023-12-28

エラー内容

 ActiveRecord::ConnectionNotEstablished:
       MySQL client is not connected

改善前の実装

.github/workflows/backend_test.yml
name: Backend Test

jobs:
  run-rspec:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        ports:
          - 3306:3306
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

改善策

ヘルスチェック周りのオプションを設定する
これにより、rspec実行前にmysqlコンテナの起動が完了していることを確認できるようになる(はず)。

改善後の実装

.github/workflows/backend_test.yml
name: Backend Test

jobs:
  run-rspec:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        ports:
          - 3306:3306
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0