Skip to content

Commit

Permalink
[git-packetline] add async-io feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 14, 2021
1 parent 8b8a1aa commit 727ad97
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ check: ## Build all code in suitable configurations
&& cargo check
cd git-packetline && cargo check --all-features \
&& cargo check \
&& cargo check --features blocking-io
&& cargo check --features blocking-io \
&& cargo check --features async-io
cd git-protocol && cargo check --all-features \
&& cargo check
cd git-url && cargo check --all-features \
Expand All @@ -119,7 +120,10 @@ unit-tests: ## run all unit tests
cargo test --all --no-fail-fast
cd git-features && cargo test && cargo test --all-features
cd git-odb && cargo test && cargo test --all-features
cd git-packetline && cargo test && cargo test --all-features
cd git-packetline && cargo test \
&& cargo test --all-features \
&& cargo test --features "blocking-io" \
&& cargo test --features "async-io"
cd git-transport && cargo test \
&& cargo test --features http-client-curl \
&& cargo test --no-default-features
Expand Down
13 changes: 9 additions & 4 deletions cargo-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ All feature toggles are additive.

### git-transport

By default, all IO related capabilities will use async IO traits from `futures-io`.

* **blocking-io**
If set, all IO will become blocking. The same types will be used preventing side-by-side usage of blocking and non-blocking IO
By default, all IO related capabilities will be missing unless one of the following is chosen.

* _mutually exclusive_
* If both are present, _blocking-io_ is chosen.
* **blocking-io**
* If set, all IO will become blocking. The same types will be used preventing side-by-side usage of blocking and non-blocking IO
* **async-io**
* Implement IO traits from `futures-io`


### git-transport

Expand Down
10 changes: 9 additions & 1 deletion git-packetline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ include = ["src/**/*"]
doctest = false

[features]
default = []
serde1 = ["serde", "bstr/serde1"]
async-io = ["futures-io"]
blocking-io = []

[[test]]
name = "non-io-packetline"
path = "tests/common-packetline.rs"
required-features = []

[[test]]
name = "async-packetline"
path = "tests/async-packetline.rs"
required-features = []
required-features = ["async-io"]

[[test]]
name = "blocking-packetline"
Expand All @@ -33,6 +40,7 @@ serde = { version = "1.0.114", optional = true, default-features = false, featur
quick-error = "2.0.0"
hex = "0.4.2"
bstr = { version = "0.2.13", default-features = false, features = ["std"] }
futures-io = { version = "0.3.15", optional = true }

[dev-dependencies]
git-odb = { version = "^0.15.0", path = "../git-odb" }
2 changes: 1 addition & 1 deletion git-packetline/tests/async-packetline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(feature = "blocking-io"))]
#[cfg(all(feature = "async-io", not(feature = "blocking-io")))]
#[test]
fn to_be_done() {
assert!(true)
Expand Down
14 changes: 0 additions & 14 deletions git-packetline/tests/blocking-packetline.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;

fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
res: std::result::Result<T, E>,
expected: impl AsRef<str>,
) {
match res {
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
}
}

#[cfg(feature = "blocking-io")]
mod blocking;
#[cfg(feature = "blocking-io")]
mod decode;
#[cfg(feature = "blocking-io")]
mod encode;
16 changes: 16 additions & 0 deletions git-packetline/tests/common-packetline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;

pub fn assert_err_display<T: std::fmt::Debug, E: std::error::Error>(
res: std::result::Result<T, E>,
expected: impl AsRef<str>,
) {
match res {
Ok(v) => assert!(false, "Expected error '{}', got value {:?}", expected.as_ref(), v),
Err(err) => assert_eq!(err.to_string(), expected.as_ref()),
}
}

#[cfg(not(any(feature = "async-io", feature = "blocking-io")))]
mod decode;
#[cfg(not(any(feature = "async-io", feature = "blocking-io")))]
mod encode;

0 comments on commit 727ad97

Please sign in to comment.