From c38a195aae1859a7569fd46263d3094d9b00db4b Mon Sep 17 00:00:00 2001 From: "Pascal S. de Kloe" Date: Sat, 20 Feb 2021 17:17:54 +0100 Subject: [PATCH] API change catchup for mqttc(1) and the integration test. --- cmd/mqttc/main.go | 11 +++++------ integration/integration_test.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/mqttc/main.go b/cmd/mqttc/main.go index f1208dd..2689750 100644 --- a/cmd/mqttc/main.go +++ b/cmd/mqttc/main.go @@ -60,7 +60,7 @@ var ( verboseFlag = flag.Bool("verbose", false, "Produces more output to "+italic+"standard error"+clear+" for debug purposes.") ) -func parseConfig() (clientID string, config *mqtt.Config, dialer mqtt.Dialer) { +func parseConfig() (clientID string, config *mqtt.Config) { var addr string switch args := flag.Args(); { case len(args) == 0: @@ -100,11 +100,11 @@ func parseConfig() (clientID string, config *mqtt.Config, dialer mqtt.Dialer) { } if *tlsFlag { - dialer = mqtt.NewTLSDialer(*netFlag, addr, &tls.Config{ + config.Dialer = mqtt.NewTLSDialer(*netFlag, addr, &tls.Config{ ServerName: *serverFlag, }) } else { - dialer = mqtt.NewDialer(*netFlag, addr) + config.Dialer = mqtt.NewDialer(*netFlag, addr) } return } @@ -136,9 +136,8 @@ func main() { log.SetOutput(io.Discard) } - clientID, config, dialer := parseConfig() - client := mqtt.NewClient(config, dialer) - err := client.VolatileSession(clientID) + clientID, config := parseConfig() + client, err := mqtt.VolatileSession(clientID, config) if err != nil { log.Fatal(err) } diff --git a/integration/integration_test.go b/integration/integration_test.go index ef380ff..10ea074 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -51,13 +51,13 @@ func race(t *testing.T, host string, deliveryLevel int) { testMessage := []byte("Hello World!") testTopic := fmt.Sprintf("test/race-%d", deliveryLevel) - client := mqtt.NewClient(&mqtt.Config{ + client, err := mqtt.VolatileSession(t.Name(), &mqtt.Config{ + Dialer: mqtt.NewDialer("tcp", net.JoinHostPort(host, "1883")), WireTimeout: time.Second, CleanSession: true, AtLeastOnceMax: testN, ExactlyOnceMax: testN, - }, mqtt.NewDialer("tcp", net.JoinHostPort(host, "1883"))) - err := client.VolatileSession(t.Name()) + }) if err != nil { t.Fatal(err) } @@ -115,24 +115,24 @@ func race(t *testing.T, host string, deliveryLevel int) { for i := 0; i < testN; i++ { go func() { defer wg.Done() - var ack <-chan error + var exchange <-chan error <-launch var err error switch deliveryLevel { case 0: err = client.Publish(nil, testMessage, testTopic) case 1: - ack, err = client.PublishAtLeastOnce(testMessage, testTopic) + exchange, err = client.PublishAtLeastOnce(testMessage, testTopic) case 2: - ack, err = client.PublishExactlyOnce(testMessage, testTopic) + exchange, err = client.PublishExactlyOnce(testMessage, testTopic) } if err != nil { t.Error("publish error:", err) return } if deliveryLevel != 0 { - for err := range ack { - t.Error("publish error:", err) + for err := range exchange { + t.Error("publish exchange error:", err) if errors.Is(err, mqtt.ErrClosed) { break }