Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ jobs:
with:
ref: ${{ github.event.inputs.sui_repo_ref || github.ref }}
- uses: taiki-e/install-action@nextest
- name: Add postgres to PATH
run: echo "/usr/lib/postgresql/14/bin" >> $GITHUB_PATH
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
Expand Down Expand Up @@ -406,40 +408,16 @@ jobs:
if: needs.diff.outputs.isRust == 'true'
timeout-minutes: 45
runs-on: [ ubuntu-ghcloud ]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgrespw
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name postgres_container
ports:
- 5432:5432
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # Pin v4.1.1
with:
ref: ${{ github.event.inputs.sui_repo_ref || github.ref }}
- uses: taiki-e/install-action@nextest
- name: Setup db
run: |
PGPASSWORD=$POSTGRES_PASSWORD psql -h localhost -U $POSTGRES_USER -c 'CREATE DATABASE sui_indexer;' -c 'ALTER SYSTEM SET max_connections = 500;'
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgrespw
- run: docker restart --time 0 postgres_container
- run: sleep 5
- name: Add postgres to PATH
run: echo "/usr/lib/postgresql/14/bin" >> $GITHUB_PATH
- name: tests-requiring-postgres
run: |
cargo nextest run --test-threads 1 --package sui-graphql-rpc --test e2e_tests --test examples_validation_tests --test dot_move_e2e --features pg_integration
cargo nextest run --test-threads 1 --package sui-graphql-rpc --lib --features pg_integration -- test_query_cost
cargo nextest run --test-threads 4 --package sui-graphql-e2e-tests --features pg_integration
cargo nextest run --test-threads 1 --package sui-cluster-test --test local_cluster_test --features pg_integration
cargo nextest run --test-threads 1 --package sui-indexer --test ingestion_tests --features pg_integration

env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
# The tests in these packages have been converted to use a temporary, ephemoral postgres database and so can be run in parallel
cargo nextest run --profile ci --package sui-indexer --package sui-graphql-e2e-tests --package sui-cluster-test --package sui-graphql-rpc --features pg_integration

41 changes: 2 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ derive-syn-parse = "0.1.5"
derive_builder = "0.12.0"
derive_more = "0.99.17"
diesel = "2.2"
diesel-derive-enum = "2.1"
diesel_migrations = "2.2"
diesel-async = "0.5"
dirs = "4.0.0"
Expand Down Expand Up @@ -439,7 +438,6 @@ rustyline = "9.1.2"
rustyline-derive = "0.7.0"
schemars = { version = "0.8.21", features = ["either"] }
scopeguard = "1.1"
serial_test = "2.0.0"
serde = { version = "1.0.144", features = ["derive", "rc"] }
serde-name = "0.2.1"
serde-reflection = "0.3.6"
Expand Down
72 changes: 41 additions & 31 deletions crates/sui-cluster-test/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use super::config::{ClusterTestOpt, Env};
use async_trait::async_trait;
use std::net::SocketAddr;
use std::path::Path;
use sui_config::local_ip_utils::get_available_port;
use sui_config::Config;
use sui_config::{PersistedConfig, SUI_KEYSTORE_FILENAME, SUI_NETWORK_CONFIG};
use sui_graphql_rpc::config::{ConnectionConfig, ServiceConfig};
use sui_graphql_rpc::test_infra::cluster::start_graphql_server_with_fn_rpc;
use sui_indexer::tempdb::TempDb;
use sui_indexer::test_utils::{start_test_indexer, ReaderWriterConfig};
use sui_keys::keystore::{AccountKeystore, FileBasedKeystore, Keystore};
use sui_sdk::sui_client_config::{SuiClientConfig, SuiEnv};
Expand Down Expand Up @@ -155,35 +157,33 @@ pub struct LocalNewCluster {
faucet_key: AccountKeyPair,
config_directory: tempfile::TempDir,
#[allow(unused)]
data_ingestion_path: tempfile::TempDir,
#[allow(unused)]
cancellation_tokens: Vec<tokio_util::sync::DropGuard>,
#[allow(unused)]
database: Option<TempDb>,
graphql_url: Option<String>,
}

impl LocalNewCluster {
#[allow(unused)]
pub fn swarm(&self) -> &Swarm {
&self.test_cluster.swarm
}

pub fn graphql_url(&self) -> &Option<String> {
&self.graphql_url
}
}

#[async_trait]
impl Cluster for LocalNewCluster {
async fn start(options: &ClusterTestOpt) -> Result<Self, anyhow::Error> {
let data_ingestion_path = tempdir()?.into_path();
// TODO: options should contain port instead of address
let fullnode_port = options.fullnode_address.as_ref().map(|addr| {
addr.parse::<SocketAddr>()
.expect("Unable to parse fullnode address")
.port()
});

let indexer_address = options.indexer_address.as_ref().map(|addr| {
addr.parse::<SocketAddr>()
.expect("Unable to parse indexer address")
});
let data_ingestion_path = tempdir()?;

let mut cluster_builder = TestClusterBuilder::new()
.enable_fullnode_events()
.with_data_ingestion_dir(data_ingestion_path.clone());
.with_data_ingestion_dir(data_ingestion_path.path().to_path_buf());

// Check if we already have a config directory that is passed
if let Some(config_dir) = options.config_dir.clone() {
Expand Down Expand Up @@ -211,10 +211,6 @@ impl Cluster for LocalNewCluster {
}
}

if let Some(rpc_port) = fullnode_port {
cluster_builder = cluster_builder.with_fullnode_rpc_port(rpc_port);
}

let mut test_cluster = cluster_builder.build().await;

// Use the wealthy account for faucet
Expand All @@ -226,36 +222,39 @@ impl Cluster for LocalNewCluster {
let fullnode_url = test_cluster.fullnode_handle.rpc_url.clone();

let mut cancellation_tokens = vec![];
if let (Some(pg_address), Some(indexer_address)) =
(options.pg_address.clone(), indexer_address)
{
// Start in writer mode
let (database, indexer_url, graphql_url) = if options.with_indexer_and_graphql {
let database = TempDb::new()?;
let pg_address = database.database().url().as_str().to_owned();
let indexer_jsonrpc_address = format!("127.0.0.1:{}", get_available_port("127.0.0.1"));
let graphql_address = format!("127.0.0.1:{}", get_available_port("127.0.0.1"));
let graphql_url = format!("http://{graphql_address}");

// Start indexer writer
let (_, _, writer_token) = start_test_indexer(
Some(pg_address.clone()),
fullnode_url.clone(),
ReaderWriterConfig::writer_mode(None, None),
data_ingestion_path.clone(),
data_ingestion_path.path().to_path_buf(),
)
.await;
cancellation_tokens.push(writer_token.drop_guard());

// Start in reader mode
// Start indexer jsonrpc service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been noticing this shift in terminology and big fan of it

let (_, _, reader_token) = start_test_indexer(
Some(pg_address),
Some(pg_address.clone()),
fullnode_url.clone(),
ReaderWriterConfig::reader_mode(indexer_address.to_string()),
data_ingestion_path,
ReaderWriterConfig::reader_mode(indexer_jsonrpc_address.clone()),
data_ingestion_path.path().to_path_buf(),
)
.await;
cancellation_tokens.push(reader_token.drop_guard());
}

if let Some(graphql_address) = &options.graphql_address {
// Start the graphql service
let graphql_address = graphql_address.parse::<SocketAddr>()?;
let graphql_connection_config = ConnectionConfig::new(
Some(graphql_address.port()),
Some(graphql_address.ip().to_string()),
options.pg_address.clone(),
Some(pg_address),
None,
None,
None,
Expand All @@ -268,7 +267,15 @@ impl Cluster for LocalNewCluster {
ServiceConfig::test_defaults(),
)
.await;
}

(
Some(database),
Some(indexer_jsonrpc_address),
Some(graphql_url),
)
} else {
(None, None, None)
};

// Let nodes connect to one another
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
Expand All @@ -279,8 +286,11 @@ impl Cluster for LocalNewCluster {
fullnode_url,
faucet_key,
config_directory: tempfile::tempdir()?,
indexer_url: options.indexer_address.clone(),
data_ingestion_path,
indexer_url,
cancellation_tokens,
database,
graphql_url,
})
}

Expand Down
6 changes: 6 additions & 0 deletions crates/sui-cluster-test/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct ClusterTestOpt {
/// URL for the indexer RPC server
#[clap(long)]
pub graphql_address: Option<String>,
/// Indicate that an indexer and graphql service should be started
///
/// Only used with a local cluster
#[clap(long)]
pub with_indexer_and_graphql: bool,
}

fn obfuscated_pg_address(val: &Option<String>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -68,6 +73,7 @@ impl ClusterTestOpt {
pg_address: None,
config_dir: None,
graphql_address: None,
with_indexer_and_graphql: false,
}
}
}
20 changes: 4 additions & 16 deletions crates/sui-cluster-test/tests/local_cluster_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,19 @@ async fn test_sui_cluster() {
use reqwest::StatusCode;
use sui_cluster_test::cluster::Cluster;
use sui_cluster_test::cluster::LocalNewCluster;
use sui_cluster_test::config::Env;
use sui_graphql_rpc::client::simple_client::SimpleClient;
use tokio::time::sleep;

telemetry_subscribers::init_for_testing();

let fullnode_rpc_port: u16 = 9020;
let indexer_rpc_port: u16 = 9124;
let pg_address = "postgres://postgres:postgrespw@localhost:5432/sui_indexer".to_string();
let graphql_address = format!("127.0.0.1:{}", 8000);

let opts = ClusterTestOpt {
env: Env::NewLocal,
faucet_address: None,
fullnode_address: Some(format!("127.0.0.1:{}", fullnode_rpc_port)),
epoch_duration_ms: Some(60000),
indexer_address: Some(format!("127.0.0.1:{}", indexer_rpc_port)),
pg_address: Some(pg_address),
config_dir: None,
graphql_address: Some(graphql_address),
with_indexer_and_graphql: true,
..ClusterTestOpt::new_local()
};

let _cluster = LocalNewCluster::start(&opts).await.unwrap();
let cluster = LocalNewCluster::start(&opts).await.unwrap();

let grphql_url: String = format!("http://127.0.0.1:{}", 8000);
let grphql_url = cluster.graphql_url().to_owned().unwrap();

sleep(std::time::Duration::from_secs(20)).await;

Expand Down
1 change: 0 additions & 1 deletion crates/sui-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ prometheus.workspace = true
rand.workspace = true # todo: cleanup test only deps
regex.workspace = true
reqwest.workspace = true
serial_test.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
Expand Down
Loading