Skip to content

Commit

Permalink
Introduce Client#destroy for a better "hard fail" in the will integra…
Browse files Browse the repository at this point in the history
…tion test
  • Loading branch information
methodmissing committed Apr 3, 2014
1 parent ee01a42 commit fb97c3d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 29 additions & 1 deletion ext/mosquitto/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static void rb_mosquitto_free_client(void *ptr)
mosquitto_loop_stop(client->mosq, true);
rb_mosquitto_client_reap_event_thread(client);
}
mosquitto_destroy(client->mosq);
if (client->mosq != NULL) mosquitto_destroy(client->mosq);
}
xfree(client);
}
Expand Down Expand Up @@ -1824,6 +1824,30 @@ static VALUE rb_mosquitto_client_want_write(VALUE obj)
return (ret == true) ? Qtrue : Qfalse;
}

/*
* call-seq:
* client.destroy -> Boolean
*
* Free memory associated with a mosquitto client instance. Used in integration tests only.
*
* @return [true] true when memory freed
* @example
* client.destroy
*
*/
static VALUE rb_mosquitto_client_destroy(VALUE obj)
{
MosquittoGetClient(obj);
if (!NIL_P(client->callback_thread)) {
mosquitto_stop_waiting_for_callbacks(client);
mosquitto_loop_stop(client->mosq, true);
rb_mosquitto_client_reap_event_thread(client);
}
mosquitto_destroy(client->mosq);
client->mosq = NULL;
return Qtrue;
}

/*
* call-seq:
* client.reconnect_delay_set(2, 10, true) -> Boolean
Expand Down Expand Up @@ -2200,4 +2224,8 @@ void _init_rb_mosquitto_client()
rb_define_method(rb_cMosquittoClient, "on_subscribe", rb_mosquitto_client_on_subscribe, -1);
rb_define_method(rb_cMosquittoClient, "on_unsubscribe", rb_mosquitto_client_on_unsubscribe, -1);
rb_define_method(rb_cMosquittoClient, "on_log", rb_mosquitto_client_on_log, -1);

/* For integration testing only (will) */
rb_define_method(rb_cMosquittoClient, "destroy", rb_mosquitto_client_destroy, 0);

}
3 changes: 1 addition & 2 deletions test/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,11 @@ def test_lwt
sleep 5

IO.for_fd(client1.socket).close
client1.destroy

sleep 5

wait{ @result }
assert_equal will, @result

client1.loop_stop(true)
end
end

0 comments on commit fb97c3d

Please sign in to comment.