Skip to content

Commit

Permalink
chore(test): switch to feature flag for test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Jul 25, 2024
1 parent 47fc926 commit 7f6b82f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 26 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/bencher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }}
BENCHER_CMD: cargo bench --all-features
BENCHER_PROJECT: socketioxide
RUSTFLAGS: --cfg=socketioxide_test

benchmark_pr:
if: github.event_name == 'workflow_dispatch' && github.event.pull_request.head.repo.full_name == github.repository
Expand Down Expand Up @@ -62,4 +61,3 @@ jobs:
BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }}
BENCHER_CMD: cargo bench --all-features
BENCHER_PROJECT: socketioxide
RUSTFLAGS: --cfg=socketioxide_test
8 changes: 0 additions & 8 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
toolchain: stable
components: rustfmt
- run: cargo fmt --all -- --check
env:
RUSTFLAGS: --cfg=socketioxide_test

test:
runs-on: ubuntu-latest
Expand All @@ -39,8 +37,6 @@ jobs:
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: cargo test --tests --all-features --workspace
env:
RUSTFLAGS: --cfg=socketioxide_test
udeps:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -90,8 +86,6 @@ jobs:

- name: check crates
run: cargo check -p socketioxide -p engineioxide --all-features
env:
RUSTFLAGS: --cfg=socketioxide_test

feature_set:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -188,8 +182,6 @@ jobs:
--tests
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true
env:
RUSTFLAGS: --cfg=socketioxide_test

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
Expand Down
9 changes: 2 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ today! As a contributor, here are the guidelines we would like you to follow:

## <a name="question"></a> Got a Question or Problem?

Please open a discussion on the [Q&A discussions](https://github.com/totodore/socketioxide/discussions) page.
Please open a discussion on the [Q&A discussions](https://github.com/totodore/socketioxide/discussions) page.
We want to keep GitHub Issues for bugs and feature requests. If you open an issue it will be moved to Discussions.

## <a name="issue"></a> Found a Bug?
Expand Down Expand Up @@ -139,11 +139,6 @@ You will need [rustc and cargo](www.rust-lang.org/tools/install).
```shell
git clone https://github.com/totodore/socketioxide
```
2. To test socketioxide don't forget to enable the flag `socketioxide_test` through the `RUSTFLAGS` environment variable:

```shell
export RUSTFLAGS="--cfg socketioxide_test"
```
2. Depending on what you want to change, clone the [socketio/engine.io-protocol](https://github.com/socketio/engine.io-protocol) repo or the [socketio/socket.io-protocol](https://github.com/socketio/socket.io-protocol) repo or both
```shell
git clone https://github.com/socketio/engine.io-protocol
Expand Down Expand Up @@ -261,4 +256,4 @@ The subject contains succinct description of the change:
### Body
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
The body should include the motivation for the change and contrast this with previous behavior.
The body should include the motivation for the change and contrast this with previous behavior.
1 change: 1 addition & 0 deletions engineioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ hyper-util = { workspace = true, features = ["tokio", "client-legacy"] }
[features]
v3 = ["memchr", "unicode-segmentation", "itoa"]
tracing = ["dep:tracing"]
__test_harness = []

[[bench]]
name = "packet_encode"
Expand Down
3 changes: 2 additions & 1 deletion engineioxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub use crate::str::Str;
pub use service::{ProtocolVersion, TransportType};
pub use socket::{DisconnectReason, Socket};

#[cfg(any(test, socketioxide_test))]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
pub use packet::*;

pub mod config;
Expand Down
6 changes: 4 additions & 2 deletions engineioxide/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ impl<D: Default + Send + Sync + 'static> std::fmt::Debug for Socket<D> {
}
}

#[cfg(socketioxide_test)]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<D> Drop for Socket<D>
where
D: Default + Send + Sync + 'static,
Expand All @@ -492,7 +493,8 @@ where
}
}

#[cfg(any(socketioxide_test, test))]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<D> Socket<D>
where
D: Default + Send + Sync + 'static,
Expand Down
1 change: 1 addition & 0 deletions socketioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ v4 = ["engineioxide/v3"]
tracing = ["dep:tracing", "engineioxide/tracing"]
extensions = []
state = ["dep:state"]
__test_harness = ["engineioxide/__test_harness"]

[dev-dependencies]
engineioxide = { path = "../engineioxide", features = ["v3", "tracing"] }
Expand Down
7 changes: 4 additions & 3 deletions socketioxide/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::sync::oneshot;
use crate::adapter::Adapter;
use crate::handler::ConnectHandler;
use crate::ns::NamespaceCtr;
use crate::parser::{self, CommonParser, Parse, Parser, TransportPayload};
use crate::parser::{self, Parse, Parser, TransportPayload};
use crate::socket::DisconnectReason;
use crate::{
errors::Error,
Expand Down Expand Up @@ -349,7 +349,8 @@ impl<A: Adapter> std::fmt::Debug for Client<A> {
}
}

#[cfg(socketioxide_test)]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<A: Adapter> Client<A> {
pub async fn new_dummy_sock(
self: Arc<Self>,
Expand Down Expand Up @@ -387,7 +388,7 @@ impl<A: Adapter> Client<A> {
}
}
});
let (p, _) = CommonParser::default().serialize(Packet {
let (p, _) = parser::CommonParser::default().serialize(Packet {
ns: ns.into(),
inner: PacketData::Connect(Some(serde_json::to_value(&auth).unwrap())),
});
Expand Down
3 changes: 2 additions & 1 deletion socketioxide/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,8 @@ impl<A: Adapter> From<Arc<Client<A>>> for SocketIo<A> {
}
}

#[cfg(any(test, socketioxide_test))]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<A: Adapter> SocketIo<A> {
/// Create a dummy socket for testing purpose with a
/// receiver to get the packets sent to the client
Expand Down
3 changes: 2 additions & 1 deletion socketioxide/src/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ impl<A: Adapter> Namespace<A> {
}
}

#[cfg(any(test, socketioxide_test))]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<A: Adapter> Namespace<A> {
pub fn new_dummy<const S: usize>(sockets: [Sid; S]) -> Arc<Self> {
let ns = Namespace::new("/".into(), || {});
Expand Down
3 changes: 2 additions & 1 deletion socketioxide/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ impl<A: Adapter> PartialEq for Socket<A> {
}
}

#[cfg(any(test, socketioxide_test))]
#[doc(hidden)]
#[cfg(feature = "__test_harness")]
impl<A: Adapter> Socket<A> {
/// Creates a dummy socket for testing purposes
pub fn new_dummy(sid: Sid, ns: Arc<Namespace<A>>) -> Socket<A> {
Expand Down

0 comments on commit 7f6b82f

Please sign in to comment.