From 5068231c5b7eb24da965bd0973c9ac213d293d6b Mon Sep 17 00:00:00 2001
From: Carl Kadie <carlk@msn.com>
Date: Thu, 1 Feb 2024 18:25:37 -0800
Subject: [PATCH] fix tests that depend on tokio

---
 Cargo.toml               |  2 +-
 examples/cloud.rs        | 52 ++++++++++++++++++++++++----------------
 tests/tests_api_cloud.rs |  3 +++
 3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 79f22f5..d7d624c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,7 @@ crate-type = ["cdylib", "rlib"]
 # https://pyo3.rs/latest/faq.html#i-cant-run-cargo-test-or-i-cant-build-in-a-cargo-workspace-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror
 [features]
 extension-module = ["pyo3/extension-module", "tokio/full"]
-default = [ "extension-module"] # cmk remove extension-module from default
+default = []
 
 [dependencies]
 thiserror = "1.0.40"
diff --git a/examples/cloud.rs b/examples/cloud.rs
index 8b0a23a..9ff2ce3 100644
--- a/examples/cloud.rs
+++ b/examples/cloud.rs
@@ -1,25 +1,35 @@
-use bed_reader::{BedCloud, BedErrorPlus, ReadOptions};
-use ndarray::s;
-use std::collections::HashSet;
+#[cfg(feature = "tokio/full")]
+mod cloud_example {
 
-#[tokio::main]
-async fn main() -> Result<(), Box<BedErrorPlus>> {
-    let url = "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/some_missing.bed";
-    let cloud_options = [("timeout", "10s")];
+    use bed_reader::{BedCloud, BedErrorPlus, ReadOptions};
+    use ndarray::s;
+    use std::collections::HashSet;
 
-    let mut bed_cloud = BedCloud::new_with_options(url, cloud_options).await?;
-    println!("{:?}", bed_cloud.iid().await?.slice(s![..5])); // Outputs ndarray: ["iid_0", "iid_1", "iid_2", "iid_3", "iid_4"]
-    println!("{:?}", bed_cloud.sid().await?.slice(s![..5])); // Outputs ndarray: ["sid_0", "sid_1", "sid_2", "sid_3", "sid_4"]
-    println!(
-        "{:?}",
-        bed_cloud.chromosome().await?.iter().collect::<HashSet<_>>()
-    );
-    // Outputs: {"12", "10", "4", "8", "19", "21", "9", "15", "6", "16", "13", "7", "17", "18", "1", "22", "11", "2", "20", "3", "5", "14"}
-    let _ = ReadOptions::builder()
-        .sid_index(bed_cloud.chromosome().await?.map(|elem| elem == "5"))
-        .f64()
-        .read_cloud(&mut bed_cloud)
-        .await?;
+    #[tokio::main]
+    async fn main() -> Result<(), Box<BedErrorPlus>> {
+        let url =
+            "https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/some_missing.bed";
+        let cloud_options = [("timeout", "10s")];
 
-    Ok(())
+        let mut bed_cloud = BedCloud::new_with_options(url, cloud_options).await?;
+        println!("{:?}", bed_cloud.iid().await?.slice(s![..5])); // Outputs ndarray: ["iid_0", "iid_1", "iid_2", "iid_3", "iid_4"]
+        println!("{:?}", bed_cloud.sid().await?.slice(s![..5])); // Outputs ndarray: ["sid_0", "sid_1", "sid_2", "sid_3", "sid_4"]
+        println!(
+            "{:?}",
+            bed_cloud.chromosome().await?.iter().collect::<HashSet<_>>()
+        );
+        // Outputs: {"12", "10", "4", "8", "19", "21", "9", "15", "6", "16", "13", "7", "17", "18", "1", "22", "11", "2", "20", "3", "5", "14"}
+        let _ = ReadOptions::builder()
+            .sid_index(bed_cloud.chromosome().await?.map(|elem| elem == "5"))
+            .f64()
+            .read_cloud(&mut bed_cloud)
+            .await?;
+
+        Ok(())
+    }
+}
+
+#[cfg(not(feature = "tokio/full"))]
+pub fn main() {
+    println!("This example requires the 'tokio/full' feature to be enabled");
 }
diff --git a/tests/tests_api_cloud.rs b/tests/tests_api_cloud.rs
index 345135a..328e1be 100644
--- a/tests/tests_api_cloud.rs
+++ b/tests/tests_api_cloud.rs
@@ -1,3 +1,5 @@
+#![cfg(feature = "tokio/full")]
+
 use bed_reader::allclose;
 use bed_reader::assert_eq_nan;
 use bed_reader::assert_error_variant;
@@ -1045,6 +1047,7 @@ async fn fill_cloud() -> Result<(), Box<BedErrorPlus>> {
     Ok(())
 }
 
+#[cfg(feature = "tokio/full")]
 #[tokio::test]
 async fn read_options_builder_cloud() -> Result<(), Box<BedErrorPlus>> {
     let url = sample_bed_url("small.bed")?;