Skip to content

Commit

Permalink
kvstore test with cargo-make invoking docker (#748)
Browse files Browse the repository at this point in the history
* kvstore test with cargo-make invoking docker
* Moved integration tests into kvstore-test crate
* subscription timeout upped to 5secs
  • Loading branch information
greg-szabo authored Dec 18, 2020
1 parent 27b3b73 commit 8bbb09b
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 77 deletions.
50 changes: 5 additions & 45 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,47 +94,7 @@ jobs:
command: test-all-features
args: -p tendermint-testgen

tendermint-integration:
runs-on: ubuntu-latest
services:
tendermint:
image: informaldev/tendermint:0.34.0
ports:
- 26656:26656
- 26657:26657
- 26660:26660
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: -p tendermint --test integration --no-fail-fast -- --ignored

tendermint-light-client-integration:
runs-on: ubuntu-latest
services:
tendermint:
image: informaldev/tendermint:0.34.0
ports:
- 26656:26656
- 26657:26657
- 26660:26660
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: -p tendermint-light-client --test integration --no-fail-fast -- --ignored

tendermint-rpc-integration:
kvstore-integration-stable:
runs-on: ubuntu-latest
services:
tendermint:
Expand All @@ -152,9 +112,9 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test-all-features
args: -p tendermint-rpc -- --ignored
args: --manifest-path tools/kvstore-test/Cargo.toml

integration-latest:
kvstore-integration-latest:
runs-on: ubuntu-latest
services:
tendermint:
Expand All @@ -173,8 +133,8 @@ jobs:
# Don't fail CI due to integration failures on unstable/unreleased versions
continue-on-error: true
with:
command: test
args: -p tendermint --test integration --no-fail-fast -- --ignored
command: test-all-features
args: --manifest-path tools/kvstore-test/Cargo.toml

nightly-coverage:
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,5 @@ zeroize = { version = "1.1", features = ["zeroize_derive"] }
k256 = { version = "0.7", optional = true, features = ["ecdsa"] }
ripemd160 = { version = "0.9", optional = true }

[dev-dependencies]
tendermint-rpc = { path = "../rpc", features = [ "http-client", "websocket-client" ] }
tokio = { version = "0.2", features = [ "macros" ] }

[features]
secp256k1 = ["k256", "ripemd160"]
2 changes: 2 additions & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
Cargo.lock
5 changes: 5 additions & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]

members = [
"kvstore-test"
]
2 changes: 2 additions & 0 deletions tools/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
36 changes: 36 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tools
This folder contains tools that we use during development and testing.

## kvstore-test
This crate allows the developers to do integration testing against a Tendermint Go endpoint. Our CI also uses it.

To run the tests locally, provided that a kvstore RPC endpoint is running on http://127.0.0.1:26657:
```shell
cargo test
```

Alternatively, you can run:
```shell
cargo test-all-features
```
which is exactly what we run in CI.

If you don't have an endpoint running, but you have Docker installed, you can ask the testing framework to fire up a
Docker container with the current stable Tendermint node. This happens automatically if you run:
```shell
cargo make
```

and all tests will run while the docker container is available. As additional help, you can run

```shell
cargo make docker-up
```

and

```shell
cargo make docker-down
```

to manage the Docker container.
17 changes: 17 additions & 0 deletions tools/kvstore-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "kvstore-test"
version = "0.1.0"
authors = ["Greg Szabo <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dev-dependencies]
futures = "0.3"
tendermint = { version = "0.17.0", path = "../../tendermint" }
tendermint-light-client = { version = "0.17.0", path = "../../light-client" }
tendermint-rpc = { version = "0.17.0", path = "../../rpc", features = [ "http-client", "websocket-client" ] }
tokio = { version = "0.2", features = [ "macros" ] }
contracts = "0.4.0"
38 changes: 38 additions & 0 deletions tools/kvstore-test/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[env]
CONTAINER_NAME = "kvstore-test"
DOCKER_IMAGE = "informaldev/tendermint:0.34.0"
HOST_RPC_PORT = 26657
CARGO_MAKE_WAIT_MILLISECONDS = 1000

[tasks.default]
clear = true
dependencies = [ "docker-up", "wait", "test", "docker-down" ]

[tasks.docker-down]
dependencies = [ "docker-stop", "docker-rm" ]

[tasks.docker-up]
command = "docker"
args = ["run", "--name", "${CONTAINER_NAME}", "--rm", "--publish", "26657:${HOST_RPC_PORT}", "--detach", "${DOCKER_IMAGE}"]
dependencies = ["docker-up-stop-old", "docker-up-rm-old"]

[tasks.test]
args = ["test-all-features"]

[tasks.docker-stop]
command = "docker"
args = ["stop", "${CONTAINER_NAME}"]
ignore_errors = true
private = true

[tasks.docker-rm]
command = "docker"
args = ["rm", "--force", "${CONTAINER_NAME}"]
ignore_errors = true
private = true

[tasks.docker-up-stop-old]
alias = "docker-stop"

[tasks.docker-up-rm-old]
alias = "docker-rm"
15 changes: 15 additions & 0 deletions tools/kvstore-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! The kvstore-test crate enables online testing against a kvstore endpoint.
//! Option 1: there is an existing kvstore RPC endpoint at 127.0.0.1:26657
//! for example in the CI setup this has been taken care of.
//! Run:
//! cargo test
//! This will execute all integration tests against the RPC endpoint.
//!
//! Option 2: the docker daemon is installed and accessible on the machine where the test will happen
//! for example: on a developer machine
//! Run:
//! cargo make
//! This will start a docker container with Tendermint and attach port 26657 to the host machine.
//! Then it will run all tests against the freshly created endpoint.
//! Make sure you installed cargo-make by running `cargo install cargo-make` first.
//!
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
//! Light Client integration tests.
//!
//! These are all ignored by default, since they test against running
//! `tendermint node --proxy_app=kvstore`. They can be run using:
//!
//! ```
//! cargo test -- --ignored
//! ```
/// If you have a kvstore app running on 127.0.0.1:26657,
/// these can be run using:
///
/// cargo test
///
/// Or else, if you have docker installed, you can tell the tests to run an endpoint,
/// by running:
///
/// cargo make
///
/// (Make sure you install cargo-make using `cargo install cargo-make` first.)
///

use tendermint_light_client::{
builder::LightClientBuilder,
Expand Down Expand Up @@ -65,7 +71,6 @@ impl EvidenceReporter for TestEvidenceReporter {
}

#[test]
#[ignore]
fn sync() {
let primary: PeerId = "BADFADAD0BEFEEDC0C0ADEADBEEFC0FFEEFACADE".parse().unwrap();
let witness: PeerId = "CEFEEDBADFADAD0C0CEEFACADE0ADEADBEEFC0FF".parse().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
//! Integration tests

/// RPC integration tests.
/// tendermint kvstore RPC integration tests.
///
/// These are all ignored by default, since they test against running
/// `tendermint node --proxy_app=kvstore`. They can be run using:
/// If you have a kvstore app running on 127.0.0.1:26657,
/// these can be run using:
///
/// cargo test
///
/// Or else, if you have docker installed, you can tell the tests to run an endpoint,
/// by running:
///
/// cargo make
///
/// (Make sure you install cargo-make using `cargo install cargo-make` first.)
///
/// ```
/// cargo test -- --ignored
/// ```
mod rpc {
use std::cmp::min;

Expand All @@ -30,7 +36,6 @@ mod rpc {

/// `/health` endpoint
#[tokio::test]
#[ignore]
async fn health() {
let result = localhost_rpc_client().health().await;

Expand All @@ -39,7 +44,6 @@ mod rpc {

/// `/abci_info` endpoint
#[tokio::test]
#[ignore]
async fn abci_info() {
let abci_info = localhost_rpc_client().abci_info().await.unwrap();

Expand All @@ -49,7 +53,6 @@ mod rpc {

/// `/abci_query` endpoint
#[tokio::test]
#[ignore]
async fn abci_query() {
let key = "unpopulated_key".parse().unwrap();
let abci_query = localhost_rpc_client()
Expand All @@ -71,7 +74,6 @@ mod rpc {

/// `/block` endpoint
#[tokio::test]
#[ignore]
async fn block() {
let height = 1u64;
let block_info = localhost_rpc_client()
Expand Down Expand Up @@ -105,7 +107,6 @@ mod rpc {

/// `/block_results` endpoint
#[tokio::test]
#[ignore]
async fn block_results() {
let height = 1u64;
let block_results = localhost_rpc_client()
Expand All @@ -119,7 +120,6 @@ mod rpc {

/// `/blockchain` endpoint
#[tokio::test]
#[ignore]
async fn blockchain() {
let max_height = 10u64;
let blockchain_info = localhost_rpc_client()
Expand All @@ -135,7 +135,6 @@ mod rpc {

/// `/commit` endpoint
#[tokio::test]
#[ignore]
async fn commit() {
let height = 1u64;
let commit_info = localhost_rpc_client()
Expand All @@ -153,15 +152,13 @@ mod rpc {

/// `/consensus_state` endpoint
#[tokio::test]
#[ignore]
async fn consensus_state() {
// TODO(thane): Test more than just the deserialization.
localhost_rpc_client().consensus_state().await.unwrap();
}

/// `/genesis` endpoint
#[tokio::test]
#[ignore]
async fn genesis() {
let genesis = localhost_rpc_client().genesis().await.unwrap(); // https://github.com/tendermint/tendermint/issues/5549

Expand All @@ -173,7 +170,6 @@ mod rpc {

/// `/net_info` endpoint integration test
#[tokio::test]
#[ignore]
async fn net_info() {
let net_info = localhost_rpc_client().net_info().await.unwrap();

Expand All @@ -182,7 +178,6 @@ mod rpc {

/// `/status` endpoint integration test
#[tokio::test]
#[ignore]
async fn status_integration() {
let status = localhost_rpc_client().status().await.unwrap();

Expand All @@ -191,7 +186,6 @@ mod rpc {
}

#[tokio::test]
#[ignore]
async fn subscription_interface() {
let (client, driver) = WebSocketClient::new("tcp://127.0.0.1:26657".parse().unwrap())
.await
Expand All @@ -215,7 +209,6 @@ mod rpc {
}

#[tokio::test]
#[ignore]
async fn transaction_subscription() {
// We run these sequentially wrapped within a single test to ensure
// that Tokio doesn't execute them simultaneously. If they are executed
Expand Down Expand Up @@ -258,7 +251,7 @@ mod rpc {
let mut cur_tx_id = 0_u32;

while !expected_tx_values.is_empty() {
let mut delay = tokio::time::delay_for(Duration::from_secs(3));
let mut delay = tokio::time::delay_for(Duration::from_secs(5));
tokio::select! {
Some(res) = subs.next() => {
let ev = res.unwrap();
Expand Down Expand Up @@ -329,7 +322,7 @@ mod rpc {
);

while expected_new_blocks > 0 && !expected_tx_values.is_empty() {
let mut timeout = tokio::time::delay_for(Duration::from_secs(3));
let mut timeout = tokio::time::delay_for(Duration::from_secs(5));
tokio::select! {
Some(res) = combined_subs.next() => {
let ev: Event = res.unwrap();
Expand Down

0 comments on commit 8bbb09b

Please sign in to comment.