Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed Apr 23, 2018
1 parent 4022eec commit cfc0b80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,23 @@ impl Connection {
}
}
fn send_data(&mut self) -> Result<usize> {
trace!("Trying to send some bytes");
let sent = match self {
trace!("Trying to send bytes");
match self {
&mut Connection::Tcp {ref mut out_buffer, ref mut connection, ref mut out_written} => {
let written = Self::manage_result(connection.write(out_buffer))?;
trace!("out_buffer: {}", out_buffer.len());
trace!("out_written: {}", out_written);
let written = Self::manage_result(connection.write(&out_buffer[*out_written..]))?;
trace!("written more: {}", written);
*out_written += written;
if out_buffer.len() == *out_written {
out_buffer.clear();
*out_written = 0;
}
Ok(written)
}
&mut Connection::Tls {ref mut tls_session, ref mut connection} => tls_session.write_tls(connection),
};
trace!("Sent {:?}", sent);
Self::manage_result(sent)
&mut Connection::Tls {ref mut tls_session, ref mut connection} =>
Self::manage_result(tls_session.write_tls(connection))
}
}
fn wants_send(&self) -> bool {
match self {
Expand Down
6 changes: 3 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ mod test {

#[test]
fn disconnect_handle_should_reset_everything_in_clean_session() {
let mut mqtt = MqttState::new(MqttOptions::new("test-id", "127.0.0.1:1883"));
let mut mqtt = MqttState::new(MqttOptions::new("test-id", "127.0.0.1:1883").set_clean_session(true));
mqtt.await_pingresp = true;
// QoS1 Publish
let publish = Publish {
Expand Down Expand Up @@ -616,7 +616,7 @@ mod test {

#[test]
fn connack_handle_should_not_return_list_of_incomplete_messages_to_be_sent_in_clean_session() {
let mut mqtt = MqttState::new(MqttOptions::new("test-id", "127.0.0.1:1883"));
let mut mqtt = MqttState::new(MqttOptions::new("test-id", "127.0.0.1:1883").set_clean_session(true));

let publish = Publish {
dup: false,
Expand Down Expand Up @@ -665,7 +665,7 @@ mod test {

if let Ok(_) = mqtt.handle_incoming_connack(connack) {
if let Some(v) = mqtt.handle_reconnection() {
assert_eq!(v.len(), 3);
assert_eq!(v.1.len(), 3);
} else {
panic!("Should return publishes to be retransmitted");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn basic_publishes_and_subscribes() {
#[test]
fn alive() {
// loggerv::init_with_level(log::LogLevel::Debug);
let client_options = MqttOptions::new("keep-alive", MOSQUITTO_ADDR).set_keep_alive(5);
let client_options = MqttOptions::new("keep-alive", MOSQUITTO_ADDR).set_keep_alive(5).set_clean_session(true);
let request = MqttClient::start(client_options).expect("Coudn't start");
assert!(request.connected());
std::thread::sleep(std::time::Duration::from_secs(10));
Expand Down Expand Up @@ -268,7 +268,7 @@ fn will() {
/// INSTANTLY publish them to new subscritions
#[test]
fn retained_messages() {
let client_options = MqttOptions::new("retain", MOSQUITTO_ADDR);
let client_options = MqttOptions::new("retain", MOSQUITTO_ADDR).set_clean_session(true);
let client = MqttClient::start(client_options).expect("Coudn't start");
let (tx, rx) = std::sync::mpsc::channel();

Expand Down

0 comments on commit cfc0b80

Please sign in to comment.