From dc14656bbc493953b20b92d4926eb0dbe48a5303 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Thu, 19 May 2022 10:13:33 +0530 Subject: [PATCH] Update scripts to run unit tests using TimescaleDB --- .github/workflows/run_unit_test.sh | 22 +++++++++++++++------- docker-compose.yml | 19 +++++++++---------- scripts/run_unit_test.sh | 30 ++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/.github/workflows/run_unit_test.sh b/.github/workflows/run_unit_test.sh index 8b80c5ab..d1854407 100755 --- a/.github/workflows/run_unit_test.sh +++ b/.github/workflows/run_unit_test.sh @@ -8,22 +8,30 @@ temp_dir=$(mktemp -d) cd $temp_dir git clone -b $(cat /tmp/git_head_ref) "https://github.com/$(cat /tmp/git_repository).git" cd ipld-eth-server +mkdir -p out ## Remove the branch and github related info. This way future runs wont be confused. rm -f /tmp/git_head_ref /tmp/git_repository -# Spin up DB -docker-compose up -d ipld-eth-db -trap "docker-compose down --remove-orphans; cd $start_dir ; rm -r $temp_dir" SIGINT SIGTERM ERR -sleep 10 +# Remove existing docker-tsdb directory +rm -rf out/docker-tsdb/ + +# Copy over files to setup TimescaleDB +ID=$(docker create vulcanize/ipld-eth-db:v4.1.1-alpha) +docker cp $ID:/app/docker-tsdb out/docker-tsdb/ +docker rm -v $ID + +# Spin up TimescaleDB +docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml up ipld-eth-db +trap "docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml down --remove-orphans --volumes; cd $start_dir ; rm -r $temp_dir" SIGINT SIGTERM ERR +sleep 45 # Remove old logs so there's no confusion, then run test rm -f /tmp/test.log /tmp/return_test.txt -PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test > /tmp/test.log +PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8066 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing_v4 make test > /tmp/test.log echo $? > /tmp/return_test.txt # Clean up -docker-compose down -v --remove-orphans +docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml down --remove-orphans --volumes cd $start_dir rm -fr $temp_dir - diff --git a/docker-compose.yml b/docker-compose.yml index 132a8d2e..dd5cefa2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,17 +2,16 @@ version: '3.2' services: ipld-eth-db: - restart: always - image: vulcanize/ipld-eth-db:v3.2.0 + restart: on-failure + depends_on: + - access-node + image: vulcanize/ipld-eth-db:v4.1.1-alpha environment: - POSTGRES_USER: "vdbm" - POSTGRES_DB: "vulcanize_testing" - POSTGRES_PASSWORD: "password" - volumes: - - vdb_db_eth_server:/var/lib/postgresql/data - ports: - - "127.0.0.1:8077:5432" - command: ["postgres", "-c", "log_statement=all"] + DATABASE_USER: "vdbm" + DATABASE_NAME: "vulcanize_testing_v4" + DATABASE_PASSWORD: "password" + DATABASE_HOSTNAME: "access-node" + DATABASE_PORT: 5432 eth-server: restart: unless-stopped diff --git a/scripts/run_unit_test.sh b/scripts/run_unit_test.sh index 27f7e2ef..1b9198d6 100755 --- a/scripts/run_unit_test.sh +++ b/scripts/run_unit_test.sh @@ -1,8 +1,26 @@ -# Clear up existing docker images and volume. -docker-compose down --remove-orphans --volumes +#!/bin/bash -docker-compose -f docker-compose.yml up -d ipld-eth-db -sleep 10 -PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test +set -e -docker-compose down --remove-orphans --volumes +mkdir -p out + +# Remove existing docker-tsdb directory +rm -rf out/docker-tsdb/ + +# Copy over files to setup TimescaleDB +ID=$(docker create vulcanize/ipld-eth-db:v4.1.1-alpha) +docker cp $ID:/app/docker-tsdb out/docker-tsdb/ +docker rm -v $ID + +# Spin up TimescaleDB +docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml up ipld-eth-db +trap "docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml down --remove-orphans --volumes; rm -rf out/" SIGINT SIGTERM ERR +sleep 45 + +# Run unit tests +go clean -testcache +PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8066 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing_v4 make test + +# Clean up +docker-compose -f out/docker-tsdb/docker-compose.test.yml -f docker-compose.yml down --remove-orphans --volumes +rm -rf out/