Skip to content

Commit 6fd7052

Browse files
committed
Improve CI build
1 parent f8cabea commit 6fd7052

File tree

11 files changed

+44
-32
lines changed

11 files changed

+44
-32
lines changed

.github/workflows/ci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: sudo-bot/action-docker-compose@latest
1616
with:
1717
# https://docs.docker.com/compose/reference/overview/
18-
cli-args: "-f docker-compose.harness.yml up -d"
18+
cli-args: "-f docker-compose.harness.yml up -d --build"
1919
- uses: actions-rs/toolchain@v1
2020
with:
2121
# No need to add `toolchain`, it will use `rust-toolchain` file instead
@@ -26,7 +26,4 @@ jobs:
2626
- name: Run `cargo make ci-flow`
2727
# Running cargo make doesn't successfully start `ganache`
2828
run: |
29-
cargo make ci-flow
30-
# set environment variables for `primitives` postgres tests
31-
env:
32-
POSTGRES_DB: sentry_leader
29+
cargo make ci-flow

adapter/Makefile.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414

1515
[tasks.ganache-up]
1616
script = '''
17-
docker-compose -f ../docker-compose.harness.yml up -d ganache \
17+
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache \
1818
&& sleep 10
1919
'''
2020

docker-compose.harness.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ version: '3.8'
22

33
services:
44
adex-postgres:
5-
image: postgres
5+
build: ./scripts/postgres
6+
# image: adex-postges
67
container_name: adex-postgres
78
restart: always
8-
volumes:
9-
- ./scripts/postgres:/docker-entrypoint-initdb.d
9+
# volumes:
10+
# - ./scripts/postgres:/docker-entrypoint-initdb.d
1011
ports:
1112
- "5432:5432"
1213
environment:
1314
POSTGRES_HOST: 'localhost'
1415
POSTGRES_USER: 'postgres'
1516
POSTGRES_PASSWORD: 'postgres'
16-
POSTGRES_MULTIPLE_DATABASES: sentry_leader,sentry_follower
17+
POSTGRES_MULTIPLE_DATABASES: harness_leader,harness_follower,sentry_leader,primitives
1718
networks:
1819
- adex-external
1920

primitives/Makefile.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
]
1414

1515
[tasks.test]
16-
env = { "POSTGRES_DB" = "sentry_leader" }
16+
env = { "POSTGRES_DB" = "primitives" }
1717

1818
[tasks.services-up]
1919
script = "docker-compose -f ../docker-compose.harness.yml up -d adex-postgres && sleep 6"

scripts/postgres/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM postgres:latest
2+
COPY ./create-multiple-postgres-db.sh /docker-entrypoint-initdb.d
3+
4+
5+
CMD ["docker-entrypoint.sh", "postgres"]

scripts/postgres/create-multiple-postgres-db.sh

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ set -e
44
set -u
55

66
function create_user_and_database() {
7-
local database=$1
8-
echo " Creating user and database '$database'"
9-
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
10-
CREATE USER $database;
11-
CREATE DATABASE $database;
12-
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
7+
local database=$1
8+
9+
echo "Creating user and database '$database'"
10+
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
11+
CREATE USER $database;
12+
CREATE DATABASE $database;
13+
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
1314
EOSQL
1415
}
1516

1617
if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
17-
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
18-
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
19-
create_user_and_database $db
20-
done
21-
echo "Multiple databases created"
18+
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
19+
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
20+
create_user_and_database $db
21+
done
22+
echo "Multiple databases created"
2223
fi

sentry/Makefile.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[tasks.test]
2-
env = { "POSTGRES_DB" = "sentry_leader" }
3-
41
[tasks.dev-test-flow]
52
description = "Development testing flow will first format the code, and than run cargo build and test"
63
category = "Development"
@@ -15,6 +12,9 @@ dependencies = [
1512
"services-down",
1613
]
1714

15+
[tasks.test]
16+
env = { "POSTGRES_DB" = "sentry_leader" }
17+
1818
[tasks.services-up]
1919
script = "docker-compose -f ../docker-compose.harness.yml up -d adex-redis adex-postgres && sleep 3"
2020

sentry/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use tokio_postgres::Config as PostgresConfig;
2929
// Re-export the Postgres PoolError for easier usages
3030
pub use deadpool_postgres::PoolError;
3131
// Re-export the redis RedisError for easier usage
32-
pub use redis::RedisError;
32+
pub use redis::{RedisError, cmd as redis_cmd};
3333

3434
pub type DbPool = deadpool_postgres::Pool;
3535

sentry/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ pub mod test_util {
562562
use adapter::DummyAdapter;
563563
use primitives::{
564564
adapter::DummyAdapterOptions,
565-
config::{configuration, DEVELOPMENT_CONFIG},
565+
config::DEVELOPMENT_CONFIG,
566566
util::tests::{discard_logger, prep_db::IDS},
567567
};
568568

@@ -575,7 +575,8 @@ pub mod test_util {
575575
Application,
576576
};
577577

578-
/// Uses development and therefore the goreli testnet addresses of the tokens
578+
/// Uses development and therefore the goerli testnet addresses of the tokens
579+
/// It still uses DummyAdapter.
579580
pub async fn setup_dummy_app() -> Application<DummyAdapter> {
580581
let config = DEVELOPMENT_CONFIG.clone();
581582
let adapter = DummyAdapter::init(

test_harness/Makefile.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ dependencies = [
1010
"local-test-flow",
1111
]
1212

13+
[tasks.test]
14+
# run tests in release because of slow unlock time of Ethereum adapter (i.e. keystore decryption)
15+
args = ["test", "--release"]
16+
1317
[tasks.local-test-flow]
1418
dependencies = ["services-up", "test-flow", "services-down"]
1519

@@ -20,7 +24,7 @@ dependencies = ["services-up", "test-flow", "services-down"]
2024
# This forces the snapshot from previous unsuccessful test runs to get destroyed.
2125
script = '''
2226
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache adex-redis adex-postgres \
23-
&& sleep 9
27+
&& sleep 6
2428
'''
2529

2630
[tasks.services-down]

test_harness/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub static VALIDATORS: Lazy<HashMap<&'static str, TestValidator>> = Lazy::new(||
100100
redis_url: "redis://127.0.0.1:6379/1".parse().unwrap(),
101101
},
102102
logger_prefix: "sentry-leader".into(),
103-
db_name: "sentry_leader".into(),
103+
db_name: "harness_leader".into(),
104104
},
105105
),
106106
(
@@ -115,7 +115,7 @@ pub static VALIDATORS: Lazy<HashMap<&'static str, TestValidator>> = Lazy::new(||
115115
redis_url: "redis://127.0.0.1:6379/2".parse().unwrap(),
116116
},
117117
logger_prefix: "sentry-follower".into(),
118-
db_name: "sentry_follower".into(),
118+
db_name: "harness_follower".into(),
119119
},
120120
),
121121
]
@@ -728,7 +728,10 @@ pub mod run {
728728
};
729729

730730
let postgres = postgres_connection(42, postgres_config).await;
731-
let redis = redis_connection(app_config.redis_url).await?;
731+
let mut redis = redis_connection(app_config.redis_url).await?;
732+
sentry::db::redis_cmd("FLUSHDB")
733+
.query_async::<_, String>(&mut redis)
734+
.await.unwrap();
732735
let campaign_remaining = CampaignRemaining::new(redis.clone());
733736

734737
setup_test_migrations(postgres.clone())

0 commit comments

Comments
 (0)