Skip to content

Commit

Permalink
refactor: simplify integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
alextes committed Sep 27, 2023
1 parent 75b9eec commit 15a0b1e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check-lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
name: Test Suite
runs-on: ubuntu-latest

# Source: https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
services:
redis:
image: redis
Expand Down
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
mod block_submission_key;
mod block_submissions;
pub mod consumer;
mod consumer;
pub mod env;
pub mod health;
mod health;
pub mod log;
pub mod server;
pub mod storage;
mod server;
mod storage;

pub use block_submission_key::BlockSubmissionKey;
pub use block_submissions::BlockSubmission;
pub use consumer::run_consume_submissions_thread;
pub use health::RedisConsumerHealth;
pub use health::RedisHealth;
pub use server::run_server_thread;
pub use server::AppState;
pub use storage::run_store_submissions_thread;

pub type JsonValue = serde_json::value::Value;

Expand Down
16 changes: 9 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use block_submission_service::{consumer, env::ENV_CONFIG, health, log, server, storage};
use block_submission_service::{
env::ENV_CONFIG, log, run_consume_submissions_thread, run_server_thread,
run_store_submissions_thread, RedisConsumerHealth, RedisHealth,
};
use fred::{pool::RedisPool, types::RedisConfig};
use futures::{channel::mpsc::channel, try_join};
use tokio::sync::Notify;
Expand Down Expand Up @@ -40,23 +43,22 @@ async fn main() -> Result<()> {
.await
.context("failed to connect to redis")?;

let redis_health = health::RedisHealth::new(redis_pool.clone());
let redis_consumer_health = health::RedisConsumerHealth::new();
let redis_health = RedisHealth::new(redis_pool.clone());
let redis_consumer_health = RedisConsumerHealth::new();

let (submissions_tx, submissions_rx) = channel(SUBMISSIONS_BUFFER_SIZE);

let cache_submissions_thread = consumer::run_consume_submissions_thread(
let cache_submissions_thread = run_consume_submissions_thread(
redis_pool.clone(),
redis_consumer_health.clone(),
shutdown_notify.clone(),
submissions_tx,
);

let store_submissions_thread =
storage::run_store_submissions_thread(redis_pool, submissions_rx, shutdown_notify.clone());
run_store_submissions_thread(redis_pool, submissions_rx, shutdown_notify.clone());

let server_thread =
server::run_server_thread(redis_health, redis_consumer_health, shutdown_notify);
let server_thread = run_server_thread(redis_health, redis_consumer_health, shutdown_notify);

try_join!(
cache_submissions_thread,
Expand Down
13 changes: 5 additions & 8 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{sync::Arc, time::Duration};

use anyhow::{Context, Result};
use block_submission_service::{
consumer, env::ENV_CONFIG, health, storage, BlockSubmission, JsonValue, STREAM_NAME,
env::ENV_CONFIG, run_consume_submissions_thread, run_store_submissions_thread, BlockSubmission,
JsonValue, RedisConsumerHealth, STREAM_NAME,
};
use fred::{
pool::RedisPool,
Expand All @@ -22,22 +23,18 @@ async fn store_block_submission() -> Result<()> {
.wait_for_connect()
.await
.context("failed to connect to redis")?;
let redis_consumer_health = health::RedisConsumerHealth::new();
let redis_consumer_health = RedisConsumerHealth::new();

let (submissions_tx, submissions_rx) = channel(4);

consumer::run_consume_submissions_thread(
run_consume_submissions_thread(
redis_pool.clone(),
redis_consumer_health.clone(),
shutdown_notify.clone(),
submissions_tx.clone(),
);

storage::run_store_submissions_thread(
redis_pool.clone(),
submissions_rx,
shutdown_notify.clone(),
);
run_store_submissions_thread(redis_pool.clone(), submissions_rx, shutdown_notify.clone());

let block_submission = {
let file = std::fs::File::open("tests/fixtures/0xffe314e3f12d726cf9f4a4babfcbfc836ef53d3144469f886423a833c853e3ef.json.gz.decompressed")?;
Expand Down

0 comments on commit 15a0b1e

Please sign in to comment.