Mysql Container Restart

김동현·2024년 9월 22일
0

Decorator

목록 보기
3/3

E2E Test DB 세팅

E2E 테스트 코드를 실행하기 위해 도커 컨테이너를 말아 올리는 과정 중 아래와 같은 에러가 나왔다.

테스트 컨테이너에 테이블 생성 스크립트를 실행할 때 등장한 에러였다.
Mysql Connection이 닫혀있다는 것이었다.

Mysql Server가 restart되는데?

{
  "name": "nesjts-drizzle",
  "scripts": {
  ...

    "db:restart": "docker-compose --profile test down && docker-compose --profile test up -d && sleep 2", // ✅ sleep 2초
    "pretest:int": "yarn db:restart && dotenv -e .env.test -- yarn run drizzle:db:push",
    "test:int": "dotenv -e .env.test -- jest -i --no-cache --config jest-int.json",
  }
  ...
}

컨테이너를 생성하고 나서 Mysql 서버가 세팅되는 것을 기다리기 위해 sleep 2초를 두고 있었다.

📌 아래 이미지는 Mysql Container가 띄어지고 난 뒤 Mysql Server가 정상적으로 실행될 때까지 터미널 내역이다.

처음 기록된 시간: 2024-09-22 19:57:05
Mysql 서버 실행 마지막 시간: 2024-09-22 19:57:14

약 9초 차이가 났다.

➡️ sleep을 아래와 같이 10초를 두니, 정상적으로 테스트 테이블이 생성 되었다.

{
  "name": "nesjts-drizzle",
  "scripts": {
  ...

    "db:restart": "docker-compose --profile test down && docker-compose --profile test up -d && sleep 10", // ✅ sleep 10초
    "pretest:int": "yarn db:restart && dotenv -e .env.test -- yarn run drizzle:db:push",
    "test:int": "dotenv -e .env.test -- jest -i --no-cache --config jest-int.json",
  }
  ...
}

P.s

sleep 10은 병을 치료하지 않고 뭔가 반창고를 붙인 느낌이었다.
Mysql 서버 세팅이 11초가 걸리면 ㅠㅠ//..

📝 컨테이너 내의 Mysql server가 실행될 때까지 기다릴 수 있는 방법에 대한 레퍼런스를 더 찾아봐야 겠다.
더해서, 왜 Root 유저에게 Shutdown 플레그를 받아 프로세스를 재시작하는 지에 대해서도 함께 찾아보아야 겠다 🤔

profile
달려보자

0개의 댓글