-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another fix for connection interrupted/resumed. Add test. (#27)
- Loading branch information
1 parent
9d41512
commit a3f33e8
Showing
4 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@testset "interrupt and resume connection" begin | ||
topic1 = "test-topic-$(Random.randstring(6))" | ||
payload1 = Random.randstring(48) | ||
client_id1 = random_client_id() | ||
@show topic1 payload1 client_id1 | ||
|
||
client = MQTTClient(new_tls_ctx()) | ||
connection = MQTTConnection(client) | ||
|
||
interruptions = Threads.Atomic{Int}(0) | ||
resumes = Threads.Atomic{Int}(0) | ||
|
||
task = connect( | ||
connection, | ||
ENV["ENDPOINT"], | ||
8883, | ||
client_id1; | ||
will = Will(topic1, AWS_MQTT_QOS_AT_LEAST_ONCE, "The client has gone offline!", false), | ||
on_connection_interrupted = (conn, error_code) -> begin | ||
Threads.atomic_add!(interruptions, 1) | ||
@warn "connection interrupted" error_code | ||
end, | ||
on_connection_resumed = (conn, return_code, session_present) -> begin | ||
Threads.atomic_add!(resumes, 1) | ||
@info "connection resumed" return_code session_present | ||
end, | ||
) | ||
@test fetch(task) == Dict(:session_present => false) | ||
|
||
# kill the MQTT connection | ||
run(`sudo ss -K dport = 8883`) | ||
|
||
wait_for(() -> resumes[] > 0, Timer(30)) | ||
@test interruptions[] == 1 | ||
@test resumes[] == 1 | ||
|
||
disconnect(connection) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a3f33e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
a3f33e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/112794
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: