Compare commits

...

7 Commits

Author SHA1 Message Date
Yury Yarashevich 65e16f5021
Merge 243ddd71ed into 3f9d88f859 2025-07-02 15:47:48 +01:00
dependabot[bot] 3f9d88f859
build(deps): bump taiki-e/install-action from 2.54.0 to 2.54.3 (#3686)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.54.0 to 2.54.3.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/install-action/compare/v2.54.0...v2.54.3)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.54.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:59:38 +00:00
dependabot[bot] 2eb801cb59
build(deps): bump taiki-e/cache-cargo-install-action from 2.1.2 to 2.2.0 (#3687)
Bumps [taiki-e/cache-cargo-install-action](https://github.com/taiki-e/cache-cargo-install-action) from 2.1.2 to 2.2.0.
- [Release notes](https://github.com/taiki-e/cache-cargo-install-action/releases)
- [Changelog](https://github.com/taiki-e/cache-cargo-install-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/taiki-e/cache-cargo-install-action/compare/v2.1.2...v2.2.0)

---
updated-dependencies:
- dependency-name: taiki-e/cache-cargo-install-action
  dependency-version: 2.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-30 22:58:36 +00:00
Rob Ede 243ddd71ed
Merge branch 'master' into web-socket-test 2023-08-01 21:09:06 +01:00
Yury Yarashevich 7a27ccffcb Added dedicated test to check web socket close procedure. 2023-08-01 17:17:17 +02:00
Yury Yarashevich a5f8534573 Check WS stream completed after close. 2023-08-01 16:39:16 +02:00
Yury Yarashevich d3911ec285 Check WS stream completed after close. 2023-08-01 16:30:37 +02:00
7 changed files with 111 additions and 7 deletions

View File

@ -49,7 +49,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -83,7 +83,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.13.0
- name: Install just, cargo-hack
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack

View File

@ -64,7 +64,7 @@ jobs:
toolchain: ${{ matrix.version.version }}
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
@ -113,7 +113,7 @@ jobs:
toolchain: nightly
- name: Install just
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just

View File

@ -24,7 +24,7 @@ jobs:
components: llvm-tools
- name: Install just, cargo-llvm-cov, cargo-nextest
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just,cargo-llvm-cov,cargo-nextest

View File

@ -77,12 +77,12 @@ jobs:
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
- name: Install just
uses: taiki-e/install-action@v2.54.0
uses: taiki-e/install-action@v2.54.3
with:
tool: just
- name: Install cargo-check-external-types
uses: taiki-e/cache-cargo-install-action@v2.1.2
uses: taiki-e/cache-cargo-install-action@v2.2.0
with:
tool: cargo-check-external-types

View File

@ -52,6 +52,10 @@ async fn common_test_code(mut srv: actix_test::TestServer, frame_size: usize) {
.unwrap();
let item = framed.next().await.unwrap().unwrap();
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
assert_eq!(true, nothing.is_ok());
assert_eq!(true, nothing.unwrap().is_none());
}
#[actix_rt::test]

View File

@ -0,0 +1,96 @@
use actix::prelude::*;
use actix_web::{web, App, HttpRequest};
use actix_web_actors::ws;
use futures_util::{SinkExt as _, StreamExt as _};
use tokio::sync::mpsc::Sender;
struct Ws {
finished: Sender<()>,
}
impl Actor for Ws {
type Context = ws::WebsocketContext<Self>;
}
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Ws {
fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
match msg {
Ok(ws::Message::Close(reason)) => ctx.close(reason),
_ => ctx.close(Some(ws::CloseCode::Normal.into())),
}
}
fn finished(&mut self, _ctx: &mut Self::Context) {
_ = self.finished.try_send(()).unwrap();
}
}
#[actix_rt::test]
async fn close_initiated_by_client() {
let (tx, mut finished) = tokio::sync::mpsc::channel(1);
let mut srv = actix_test::start(move || {
let tx = tx.clone();
App::new().service(web::resource("{anything:.*}").to(
move |req: HttpRequest, stream: web::Payload| {
let tx: Sender<()> = tx.clone();
async move { ws::WsResponseBuilder::new(Ws { finished: tx }, &req, stream).start() }
},
))
});
let mut framed = srv.ws().await.unwrap();
framed
.send(ws::Message::Close(Some(ws::CloseCode::Normal.into())))
.await
.unwrap();
let item = framed.next().await.unwrap().unwrap();
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
assert_eq!(true, nothing.is_ok());
assert_eq!(true, nothing.unwrap().is_none());
let finished =
actix_rt::time::timeout(std::time::Duration::from_secs(1), finished.recv()).await;
assert_eq!(true, finished.is_ok());
assert_eq!(Some(()), finished.unwrap());
}
#[actix_rt::test]
async fn close_initiated_by_server() {
let (tx, mut finished) = tokio::sync::mpsc::channel(1);
let mut srv = actix_test::start(move || {
let tx = tx.clone();
App::new().service(web::resource("{anything:.*}").to(
move |req: HttpRequest, stream: web::Payload| {
let tx: Sender<()> = tx.clone();
async move { ws::WsResponseBuilder::new(Ws { finished: tx }, &req, stream).start() }
},
))
});
let mut framed = srv.ws().await.unwrap();
framed
.send(ws::Message::Text("I'll initiate close by server".into()))
.await
.unwrap();
let item = framed.next().await.unwrap().unwrap();
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
framed
.send(ws::Message::Close(Some(ws::CloseCode::Normal.into())))
.await
.unwrap();
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
assert_eq!(true, nothing.is_ok());
assert_eq!(true, nothing.unwrap().is_none());
let finished =
actix_rt::time::timeout(std::time::Duration::from_secs(1), finished.recv()).await;
assert_eq!(true, finished.is_ok());
assert_eq!(Some(()), finished.unwrap());
}

View File

@ -65,4 +65,8 @@ async fn test_simple() {
let item = framed.next().await.unwrap().unwrap();
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
assert_eq!(true, nothing.is_ok());
assert_eq!(true, nothing.unwrap().is_none());
}