Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): add engineio ci for v4 and ci for v3 & v4 #56

Merged
merged 8 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 67 additions & 5 deletions .github/workflows/engineio-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
pull_request:
branches:
- main
- develop

jobs:
e2e_v3:
Expand All @@ -29,11 +28,74 @@ jobs:
- name: Install deps & run tests
run: |
cd engine.io-protocol/test-suite && npm install && cd ../..
cargo build --bin engineioxide-e2e --release --features v3 --no-default-features
cargo run --bin engineioxide-e2e --release --features v3 --no-default-features > v3_server.txt & npm --prefix engine.io-protocol/test-suite test > v3_client.txt
cargo build --bin engineioxide-e2e --release --features engineio-v3 --no-default-features
cargo run --bin engineioxide-e2e --release --features engineio-v3 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt
- name: Server output
if: always()
run: cat v3_server.txt
run: cat server.txt
- name: Client output
if: always()
run: cat v3_client.txt
run: cat client.txt
e2e_v4:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions/checkout@v3
with:
repository: socketio/engine.io-protocol
path: engine.io-protocol
ref: main
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install deps & run tests
run: |
cd engine.io-protocol/test-suite && npm install && cd ../..
cargo build --bin engineioxide-e2e --release --features engineio-v4 --no-default-features
cargo run --bin engineioxide-e2e --release --features engineio-v4 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt
- name: Server output
if: always()
run: cat server.txt
- name: Client output
if: always()
run: cat client.txt
e2e_full:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions/checkout@v3
with:
repository: socketio/engine.io-protocol
path: engine.io-protocol-v3
ref: v3
- uses: actions/checkout@v3
with:
repository: socketio/engine.io-protocol
path: engine.io-protocol-v4
ref: main
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install deps & run tests
run: |
cd engine.io-protocol-v3/test-suite && npm install && cd ../..
cd engine.io-protocol-v4/test-suite && npm install && cd ../..
cargo build --bin engineioxide-e2e --release --features engineio-v3,engineio-v4 --no-default-features
cargo run --bin engineioxide-e2e --release --features engineio-v3,engineio-v4 --no-default-features > server.txt & npm --prefix engine.io-protocol-v4/test-suite test > client_v4.txt & npm --prefix engine.io-protocol-v3/test-suite test > client_v3.txt
- name: Server output
if: always()
run: cat server.txt
- name: Client v3 output
if: always()
run: cat client_v3.txt
- name: Client v4 output
if: always()
run: cat client_v4.txt
9 changes: 7 additions & 2 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.3.0"
edition = "2021"

[dependencies]
engineioxide = { path = "../engineioxide" }
engineioxide = { path = "../engineioxide", default-features = false }
socketioxide = { path = "../socketioxide" }
hyper = { version = "0.14.26" }
tokio = { version = "1.13.0", features = ["full"] }
Expand All @@ -20,4 +20,9 @@ path = "src/socketioxide.rs"

[[bin]]
name = "engineioxide-e2e"
path = "src/engineioxide.rs"
path = "src/engineioxide.rs"


[features]
engineio-v3 = ["engineioxide/v3"]
engineio-v4 = ["engineioxide/v4"]
22 changes: 11 additions & 11 deletions engineioxide/src/payload/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn v3_string_decoder(
(true, i + 1 - old_len) // Mark as done and set the used bytes count
}
None if state.end_of_stream && remaining - available.len() == 0 => {
return None;
return Some((Err(Error::InvalidPacketLength), state));
} // Reached end of stream and end of bufferered chunks without finding the separator
None => (false, available.len()), // Continue reading more data
}
Expand Down Expand Up @@ -415,7 +415,7 @@ mod tests {
async fn string_payload_iterator_v3() {
assert!(cfg!(feature = "v3"));

let data = Full::new(Bytes::from("4:4foo3:4€f10:4faaaaaaaaa"));
let data = Full::new(Bytes::from("4:4foo3:4€f11:4faaaaaaaaa"));
let payload = v3_string_decoder(data, MAX_PAYLOAD);
futures::pin_mut!(payload);
assert!(matches!(
Expand All @@ -428,20 +428,20 @@ mod tests {
));
assert!(matches!(
payload.next().await.unwrap().unwrap(),
Packet::Message(msg) if msg == "faaaaaaaa"
Packet::Message(msg) if msg == "faaaaaaaaa"
));
assert_eq!(payload.next().await.is_none(), true);
assert!(payload.next().await.is_none());
}

#[cfg(feature = "v3")]
#[tokio::test]
async fn binary_payload_iterator_v3() {
assert!(cfg!(feature = "v3"));

const PAYLOAD: &'static [u8] = &[
const PAYLOAD: &[u8] = &[
0, 9, 255, 52, 104, 101, 108, 108, 111, 226, 130, 172, 1, 5, 255, 4, 1, 2, 3, 4,
];
const BINARY_PAYLOAD: &'static [u8] = &[1, 2, 3, 4];
const BINARY_PAYLOAD: &[u8] = &[1, 2, 3, 4];
let data = Full::new(Bytes::from(PAYLOAD));
let payload = v3_binary_decoder(data, MAX_PAYLOAD);
futures::pin_mut!(payload);
Expand All @@ -453,7 +453,7 @@ mod tests {
payload.next().await.unwrap().unwrap(),
Packet::BinaryV3(msg) if msg == BINARY_PAYLOAD
));
assert_eq!(payload.next().await.is_none(), true);
assert!(payload.next().await.is_none());
}

#[cfg(feature = "v3")]
Expand Down Expand Up @@ -481,7 +481,7 @@ mod tests {
payload.next().await.unwrap().unwrap(),
Packet::Message(msg) if msg == "baaaaaaaar"
));
assert_eq!(payload.next().await.is_none(), true);
assert!(payload.next().await.is_none());
}
}

Expand All @@ -490,10 +490,10 @@ mod tests {
async fn binary_payload_stream_v3() {
assert!(cfg!(feature = "v3"));

const PAYLOAD: &'static [u8] = &[
const PAYLOAD: &[u8] = &[
0, 9, 255, 52, 104, 101, 108, 108, 111, 226, 130, 172, 1, 5, 255, 4, 1, 2, 3, 4,
];
const BINARY_PAYLOAD: &'static [u8] = &[1, 2, 3, 4];
const BINARY_PAYLOAD: &[u8] = &[1, 2, 3, 4];

for i in 1..PAYLOAD.len() {
println!("payload stream v3 chunk size: {i}");
Expand All @@ -510,7 +510,7 @@ mod tests {
payload.next().await.unwrap().unwrap(),
Packet::BinaryV3(msg) if msg == BINARY_PAYLOAD
));
assert_eq!(payload.next().await.is_none(), true);
assert!(payload.next().await.is_none());
}
}

Expand Down
2 changes: 1 addition & 1 deletion engineioxide/src/payload/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ mod tests {
#[cfg(feature = "v3")]
#[tokio::test]
async fn encode_v3b64_payload() {
const PAYLOAD: &'static str = "7:4hello€10:b4AQIDBA==7:4hello€";
const PAYLOAD: &str = "7:4hello€10:b4AQIDBA==7:4hello€";
let (tx, rx) = tokio::sync::mpsc::channel::<Packet>(10);
let mutex = Mutex::new(rx);
let rx = mutex.lock().await;
Expand Down
5 changes: 4 additions & 1 deletion engineioxide/src/payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ pub fn decoder(

#[cfg(all(feature = "v3", not(feature = "v4")))]
{
let is_binary =
body.headers().get(CONTENT_TYPE) == Some(&"application/octet-stream".parse().unwrap());
use futures::future::Either;
use http::header::CONTENT_TYPE;
if is_binary {
Either::Left(decoder::v3_binary_decoder(body, max_payload))
} else {
Either::Right(decoder::v3_binary_decoder(body, max_payload))
Either::Right(decoder::v3_string_decoder(body, max_payload))
}
}
#[cfg(all(feature = "v4", not(feature = "v3")))]
Expand Down
4 changes: 2 additions & 2 deletions engineioxide/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ mod tests {
fn request_info_polling_with_bin_by_default() {
let req = build_request("http://localhost:3000/socket.io/?EIO=3&transport=polling");
let req = RequestInfo::parse(&req).unwrap();
assert_eq!(req.b64, false);
assert!(!req.b64);
}

#[test]
Expand All @@ -390,7 +390,7 @@ mod tests {

let req = build_request("http://localhost:3000/socket.io/?EIO=3&transport=polling&b64=1");
let req = RequestInfo::parse(&req).unwrap();
assert_eq!(req.b64, true);
assert!(req.b64);
}

#[test]
Expand Down
Loading