Skip to content

Commit

Permalink
Merge pull request #360 from jeremyandrews/tungstenite
Browse files Browse the repository at this point in the history
update tungstenite version to 0.15
  • Loading branch information
jeremyandrews committed Sep 3, 2021
2 parents af6fd76 + 0dc7131 commit f8e1954
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- remove `Clone` trait from `GooseUser` and `GooseAttack`
- update `GooseTaskSet::set_wait_time()` to accept `std::time::Duration` instead of `usize` allowing more granularity (API change)
- use request name when displaying errors to avoid having a large volume of distinct error for the same endpoint when using path parameters
- updated `tungstenite` dependency to [`0.15`](https://github.com/snapview/tungstenite-rs/blob/master/CHANGELOG.md)

## 0.13.3 August 25, 2021
- document GooseConfiguration fields that were only documented as gumpdrop parameters (in order to generate new lines in the help output) so now they're also documented in the code
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tokio = { version = "1", features = [
"sync",
] }
tokio-tungstenite = "0.15"
tungstenite = "0.14"
tungstenite = "0.15"
url = "2"

# optional dependencies
Expand Down
18 changes: 10 additions & 8 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::str;
use std::str::FromStr;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
use tungstenite::Message;
use tokio_tungstenite::tungstenite::Message;

/// Goose currently supports two different Controller protocols: telnet and WebSocket.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -293,13 +293,15 @@ type GooseControllerExit = bool;
type GooseControllerTelnetMessage = [u8; 1024];

/// The WebSocket Controller message buffer.
type GooseControllerWebSocketMessage =
std::result::Result<tungstenite::Message, tungstenite::Error>;
type GooseControllerWebSocketMessage = std::result::Result<
tokio_tungstenite::tungstenite::Message,
tokio_tungstenite::tungstenite::Error,
>;

/// Simplify the GooseControllerExecuteCommand trait definition for WebSockets.
type GooseControllerWebSocketSender = futures::stream::SplitSink<
tokio_tungstenite::WebSocketStream<tokio::net::TcpStream>,
tungstenite::Message,
tokio_tungstenite::tungstenite::Message,
>;

/// This state object is created in the main Controller thread and then passed to the specific
Expand Down Expand Up @@ -844,8 +846,8 @@ impl GooseControllerExecuteCommand<GooseControllerWebSocketSender> for GooseCont
// If exiting, notify the WebSocket client that this connection is closing.
if exit_controller
&& socket
.send(Message::Close(Some(tungstenite::protocol::CloseFrame {
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
.send(Message::Close(Some(tokio_tungstenite::tungstenite::protocol::CloseFrame {
code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Normal,
reason: std::borrow::Cow::Borrowed("exit"),
})))
.await
Expand Down Expand Up @@ -886,8 +888,8 @@ impl GooseControllerExecuteCommand<GooseControllerWebSocketSender> for GooseCont
// If exiting, notify the WebSocket client that this connection is closing.
if exit_controller
&& socket
.send(Message::Close(Some(tungstenite::protocol::CloseFrame {
code: tungstenite::protocol::frame::coding::CloseCode::Normal,
.send(Message::Close(Some(tokio_tungstenite::tungstenite::protocol::CloseFrame {
code: tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode::Normal,
reason: std::borrow::Cow::Borrowed("shutdown"),
})))
.await
Expand Down
11 changes: 6 additions & 5 deletions tests/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use httpmock::{Method::GET, Mock, MockServer};
use std::io::{Read, Write};
use std::net::TcpStream;
use std::{str, thread, time};
use tungstenite::Message;
use tokio_tungstenite::tungstenite::Message;

use goose::config::GooseConfiguration;
use goose::controller::{
Expand Down Expand Up @@ -48,11 +48,11 @@ struct TestState {
telnet_stream: Option<TcpStream>,
// A TCP socket if testing the WebSocket Controller.
#[cfg(not(feature = "rustls-tls"))]
websocket_stream: Option<tungstenite::WebSocket<std::net::TcpStream>>,
websocket_stream: Option<tokio_tungstenite::tungstenite::WebSocket<std::net::TcpStream>>,
#[cfg(feature = "rustls-tls")]
websocket_stream: Option<
tungstenite::WebSocket<
tungstenite::stream::Stream<
tokio_tungstenite::tungstenite::WebSocket<
tokio_tungstenite::tungstenite::stream::Stream<
std::net::TcpStream,
rustls::StreamOwned<rustls::ClientSession, TcpStream>,
>,
Expand Down Expand Up @@ -638,7 +638,8 @@ fn update_state(test_state: Option<TestState>, test_type: &TestType) -> TestStat
let websocket_controller: bool;
let websocket_stream = match test_type {
TestType::WebSocket => {
let (mut stream, _) = tungstenite::client::connect("ws://127.0.0.1:5117").unwrap();
let (mut stream, _) =
tokio_tungstenite::tungstenite::client::connect("ws://127.0.0.1:5117").unwrap();
// Send an empty message so the client performs a handshake.
stream.write_message(Message::Text("".into())).unwrap();
// Ignore the error that comes back.
Expand Down

0 comments on commit f8e1954

Please sign in to comment.