-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate tests to integ tests to run as separate processes
- Loading branch information
Showing
14 changed files
with
172 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test(flavor = "multi_thread")] | ||
async fn block_in_place_strategy() { | ||
use compute_heavy_future_executor::{initialize_block_in_place_strategy, spawn_compute_heavy_future}; | ||
|
||
initialize_block_in_place_strategy(); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use compute_heavy_future_executor::{initialize_current_context_strategy, spawn_compute_heavy_future}; | ||
|
||
#[tokio::test] | ||
async fn current_context_strategy() { | ||
initialize_current_context_strategy(); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::any::Any; | ||
|
||
use compute_heavy_future_executor::{initialize_custom_executor_strategy, CustomExecutorClosure}; | ||
|
||
#[tokio::test] | ||
#[should_panic] | ||
async fn custom_strategy_illegal_closure() { | ||
// this closure overwrites the input type, causing a mismatch | ||
let closure: CustomExecutorClosure = Box::new(|_| { | ||
Box::new(async move { | ||
Ok(Box::new("foo") as Box<dyn Any + Send>) | ||
}) | ||
}); | ||
// this should panic due to bad closure | ||
initialize_custom_executor_strategy(closure).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use compute_heavy_future_executor::{initialize_custom_executor_strategy, spawn_compute_heavy_future, CustomExecutorClosure}; | ||
|
||
#[tokio::test] | ||
async fn custom_strategy_legal_closure() { | ||
let closure: CustomExecutorClosure = Box::new(|fut| { | ||
Box::new(async move { | ||
let res = fut.await; | ||
Ok(res) | ||
}) | ||
}); | ||
|
||
initialize_custom_executor_strategy(closure).await; | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
async fn custom_strategy_legal_closure_tokio_spawn() { | ||
use compute_heavy_future_executor::{initialize_custom_executor_strategy, spawn_compute_heavy_future, CustomExecutorClosure}; | ||
|
||
let closure: CustomExecutorClosure = Box::new(|fut| { | ||
Box::new( | ||
async move { | ||
let handle = tokio::task::spawn(async move { fut.await }); | ||
handle.await.map_err(|err| err.into()) | ||
} | ||
) | ||
}); | ||
initialize_custom_executor_strategy(closure).await; | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
async fn default_to_current_context_tokio_single_threaded() { | ||
use compute_heavy_future_executor::spawn_compute_heavy_future; | ||
|
||
// this is a tokio test but we haven't enabled the tokio config flag | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test(flavor = "multi_thread")] | ||
async fn default_to_current_context_tokio_multi_threaded() { | ||
use compute_heavy_future_executor::spawn_compute_heavy_future; | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[cfg(not(feature = "tokio"))] | ||
#[tokio::test] | ||
async fn default_to_current_context_non_tokio() { | ||
use compute_heavy_future_executor::{initialize_current_context_strategy, spawn_compute_heavy_future}; | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use compute_heavy_future_executor::{initialize_spawn_blocking_strategy, spawn_compute_heavy_future}; | ||
|
||
|
||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
async fn spawn_blocking_strategy() { | ||
initialize_spawn_blocking_strategy(); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
async fn secondary_tokio_runtime_strategy() { | ||
use compute_heavy_future_executor::{initialize_secondary_tokio_runtime_strategy, spawn_compute_heavy_future}; | ||
|
||
initialize_secondary_tokio_runtime_strategy(); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use compute_heavy_future_executor::initialize_current_context_strategy; | ||
|
||
#[tokio::test] | ||
#[should_panic] | ||
async fn multiple_initializes_panic() { | ||
initialize_current_context_strategy(); | ||
initialize_current_context_strategy(); | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/secondary_tokio_runtime_strategy_disallowed_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
#[should_panic] | ||
async fn secondary_tokio_runtime_strategy_disallowed_config() { | ||
use compute_heavy_future_executor::{initialize_secondary_tokio_runtime_strategy_and_config, spawn_compute_heavy_future}; | ||
|
||
initialize_secondary_tokio_runtime_strategy_and_config(Some(30), Some(50)); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use compute_heavy_future_executor::{initialize_spawn_blocking_strategy, spawn_compute_heavy_future}; | ||
|
||
|
||
#[cfg(feature = "tokio")] | ||
#[tokio::test] | ||
async fn spawn_blocking_strategy() { | ||
initialize_spawn_blocking_strategy(); | ||
|
||
let future = async { 5 }; | ||
|
||
let res = spawn_compute_heavy_future(future).await.unwrap(); | ||
assert_eq!(res, 5); | ||
|
||
} |