Skip to content

Commit

Permalink
Add paho wrapper test for keepalive (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Jan 25, 2020
1 parent e3cf9f2 commit c8aadbe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion keepalive_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ func TestIntegration_KeepAlive(t *testing.T) {
}
})
}

}
29 changes: 29 additions & 0 deletions paho/paho_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,32 @@ func TestIntegration_PublishSubscribe(t *testing.T) {
})
}
}

func TestIntegration_KeepAlive(t *testing.T) {
for name, recon := range map[string]bool{"Reconnect": true, "NoReconnect": false} {
t.Run(name, func(t *testing.T) {
opts := paho.NewClientOptions()
server, err := url.Parse("mqtt://localhost:1883")
if err != nil {
t.Fatalf("Unexpected error: '%v'", err)
}
opts.Servers = []*url.URL{server}
opts.AutoReconnect = recon
opts.ClientID = "PahoWrapper" + name
opts.KeepAlive = 1

cli := NewClient(opts)
token := cli.Connect()
if !token.WaitTimeout(5 * time.Second) {
t.Fatal("Connect timeout")
}

// Without keepalive, broker should disconnect on t=1.5s.
time.Sleep(3 * time.Second)

if !cli.IsConnected() {
t.Errorf("Connection is unexpectedly closed")
}
})
}
}

0 comments on commit c8aadbe

Please sign in to comment.