Skip to content

Commit

Permalink
ci: use nextest for running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Mar 15, 2024
1 parent 2f61c6f commit 3891fdd
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 125 deletions.
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
};

ci = pkgs.callPackage ./nix/ci.nix {
tests = builtCrates.packages.tests;
binaries = builtCrates.binaries;
};
in
Expand Down
54 changes: 5 additions & 49 deletions nix/ci.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, tests, binaries, ... }:
{ pkgs, binaries, ... }:
/* CI/CD related scripts and pipelines.
This file is used to dynamically generate the Buildkite pipeline (see `pipeline` down below).
Expand All @@ -9,36 +9,6 @@
- `binaries`: a list of binaries in the crate. This is generated from the `crates` definition in flake.nix.
*/
let
/* Run all unit tests.
*/
ci-test = pkgs.writeShellApplication {
name = "ci-test";
runtimeInputs = [ tests ];
text = ''
echo "--- Running unit tests"
for testBin in ${tests}/bin/*; do
echo "Running ''${testBin}"
''${testBin}
done
'';
};

/* Run all integration tests.
This tests take longer to run so they're run separately.
*/
ci-e2e-test = pkgs.writeShellApplication {
name = "ci-e2e-test";
runtimeInputs = [ tests ];
text = ''
echo "--- Running e2e tests"
for testBin in ${tests}/bin/*; do
echo "Running ''${testBin}"
''${testBin} --ignored
done
'';
};

/* Prepares the image to be uploaded to Buildkite.
Notice that this script expects the image to be in `./result`.
Expand Down Expand Up @@ -222,26 +192,22 @@ let
steps = [
{
label = ":nix: Checks";
command = "nix flake check";
}
{
label = ":rust: Build tests";
command = "nix build .#tests";
command = "nix flake check -L";
}
{
wait = { };
}
{
label = ":test_tube: Run unit tests";
commands = [
"nix develop .#test -c ci-test"
"nix build .#unit-tests -L"
];
}
{
label = ":test_tube: Run e2e tests";
commands = [
"podman system service --time=0 unix:///var/run/docker.sock &"
"nix develop .#test -c ci-e2e-test"
"nix build .#integration-tests -L"
];
}
{
Expand Down Expand Up @@ -378,21 +344,11 @@ in

shell = {
ci = pkgs.mkShell {
buildInputs = with pkgs; [
buildInputs = [
ci-prepare-image
ci-prepare-binary
ci-publish-image
];
};

test = pkgs.mkShell {
buildInputs = with pkgs; [
# used by e2e tests to start test containers
docker-client

ci-test
ci-e2e-test
];
};
};
}
54 changes: 16 additions & 38 deletions nix/crates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let

buildArgs = ({
nativeBuildInputs = with pkgs; [
cargo-nextest
clang
cmake
llvmPackages.libclang.lib
Expand Down Expand Up @@ -71,45 +72,21 @@ let
version = "0.0.0";
});

testBinaries = craneLib.buildPackage (commonArgs // {
unitTests = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
pname = "apibara-test";
pname = "apibara";
version = "0.0.0";
cargoExtraArgs = "--tests";
doCheck = false;

installPhaseCommand = ''
local dest="$out"
local log="$cargoBuildLog"
if ! [ -f "''${log}" ]; then
echo "unable to install, cargo build log does not exist at: ''${log}"
false
fi
echo "searching for tests to install from cargo build log at ''${log}"
local logs
logs=$(jq -R 'fromjson?' <"''${log}")
local select_test='select(.reason == "compiler-artifact" and .profile.test == true)'
local select_bins="''${select_test} | .executable | select(.!= null)"
function installArtifacts() {
local loc=''${1?:missing}
mkdir -p "''${loc}"
while IFS= read -r to_install; do
echo "installing ''${to_install}"
cp "''${to_install}" "''${loc}"
done
rmdir --ignore-fail-on-non-empty "''${loc}"
}
cargoNextestExtraArgs = "-E 'kind(lib)'";
});

echo "''${logs}" | jq -r "''${select_bins}" | installArtifacts "''${dest}/bin"
echo "searching for tests complete"
'';
integrationTests = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
pname = "apibara";
version = "0.0.0";
cargoNextestExtraArgs = "-E 'kind(test)'";
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
pkgs.docker-client
];
});

/* Build a crate from a path, optionally overriding the binary name.
Expand Down Expand Up @@ -253,7 +230,7 @@ let
# Binaries as packages.
# binaryPackages = builtins.mapAttrs (_: crate: crate.bin) binaries;
in
rec {
{
checks = {
inherit cargoFmt cargoClippy;
};
Expand All @@ -270,6 +247,7 @@ rec {

packages = images // binariesUniversal // {
all-crates = allCrates;
tests = testBinaries;
unit-tests = unitTests;
integration-tests = integrationTests;
};
}
1 change: 0 additions & 1 deletion sdk/tests/test_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use apibara_sdk::{configuration, ClientBuilder, Configuration, Uri};
use futures_util::{StreamExt, TryStreamExt};

// #[tokio::test]
// #[ignore]
#[allow(dead_code)]
async fn test_apibara_high_level_api() -> Result<(), Box<dyn std::error::Error>> {
let (config_client, config_stream) = configuration::channel(128);
Expand Down
4 changes: 0 additions & 4 deletions sinks/sink-common/tests/test_etcd_persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ where
}

#[tokio::test]
#[ignore]
async fn test_single_indexer() {
let docker = clients::Cli::default();
let etcd = docker.run(Etcd::default());
Expand Down Expand Up @@ -51,7 +50,6 @@ async fn test_single_indexer() {
}

#[tokio::test]
#[ignore]
async fn test_multiple_indexers() {
let docker = clients::Cli::default();
let etcd = docker.run(Etcd::default());
Expand Down Expand Up @@ -96,7 +94,6 @@ async fn test_multiple_indexers() {

// Flaky test
// #[tokio::test]
// #[ignore]
#[allow(dead_code)]
async fn test_lock_unlock_single() {
let docker = clients::Cli::default();
Expand All @@ -115,7 +112,6 @@ async fn test_lock_unlock_single() {
}

#[tokio::test]
#[ignore]
async fn test_lock_unlock_multiple() {
let docker = clients::Cli::default();
let etcd = docker.run(Etcd::default());
Expand Down
2 changes: 0 additions & 2 deletions sinks/sink-common/tests/test_redis_persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub fn new_redis_image() -> GenericImage {
}

#[tokio::test]
#[ignore]
async fn test_single_indexer() {
let docker = clients::Cli::default();
let redis = docker.run(new_redis_image());
Expand Down Expand Up @@ -45,7 +44,6 @@ async fn test_single_indexer() {
}

#[tokio::test]
#[ignore]
async fn test_multiple_indexers() {
let docker = clients::Cli::default();
let redis = docker.run(new_redis_image());
Expand Down
8 changes: 0 additions & 8 deletions sinks/sink-mongo/tests/test_multi_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ fn new_batch_with_extra(
}

#[tokio::test]
#[ignore]
async fn test_handle_data() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -113,7 +112,6 @@ async fn test_handle_data() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_data_empty_collection() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -208,19 +206,16 @@ async fn test_handle_invalidate_all(invalidate_from: &Option<Cursor>) -> Result<
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_genesis() -> Result<(), SinkError> {
test_handle_invalidate_all(&None).await
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_block_zero() -> Result<(), SinkError> {
test_handle_invalidate_all(&Some(new_cursor(0))).await
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -292,7 +287,6 @@ async fn test_handle_invalidate() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_with_extra_condition() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -372,7 +366,6 @@ async fn test_handle_invalidate_with_extra_condition() -> Result<(), SinkError>
}

#[tokio::test]
#[ignore]
async fn test_handle_data_in_entity_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -528,7 +521,6 @@ async fn test_handle_data_in_entity_mode() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_in_entity_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down
9 changes: 0 additions & 9 deletions sinks/sink-mongo/tests/test_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn new_batch_with_extra(start_cursor: &Option<Cursor>, end_cursor: &Cursor, extr
}

#[tokio::test]
#[ignore]
async fn test_handle_data() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -151,19 +150,16 @@ async fn test_handle_invalidate_all(invalidate_from: &Option<Cursor>) -> Result<
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_genesis() -> Result<(), SinkError> {
test_handle_invalidate_all(&None).await
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_block_zero() -> Result<(), SinkError> {
test_handle_invalidate_all(&Some(new_cursor(0))).await
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -226,7 +222,6 @@ async fn test_handle_invalidate() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_with_extra_condition() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -294,7 +289,6 @@ async fn test_handle_invalidate_with_extra_condition() -> Result<(), SinkError>
}

#[tokio::test]
#[ignore]
async fn test_handle_data_in_entity_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -444,7 +438,6 @@ async fn test_handle_data_in_entity_mode() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_invalidate_in_entity_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -564,7 +557,6 @@ async fn test_handle_invalidate_in_entity_mode() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_handle_data_batch_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down Expand Up @@ -671,7 +663,6 @@ async fn test_handle_data_batch_mode() -> Result<(), SinkError> {
}

#[tokio::test]
#[ignore]
async fn test_invalidate_batch_mode() -> Result<(), SinkError> {
let docker = clients::Cli::default();
let mongo = docker.run(new_mongo_image());
Expand Down
1 change: 0 additions & 1 deletion sinks/sink-parquet/tests/test_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn get_file_names(output_dir: &TempDir, path: &str) -> Option<Vec<OsString>> {
}

#[tokio::test]
#[ignore]
async fn test_handle_data() -> Result<(), SinkError> {
let parquet_batch_size = 10;
let (output_dir, mut sink) = new_sink(parquet_batch_size).await;
Expand Down
Loading

0 comments on commit 3891fdd

Please sign in to comment.