Remove context leak warnings

This commit is contained in:
Jerome Sautret
2019-12-26 15:51:19 +01:00
parent 600f7d5246
commit 6e2ba9ca57
3 changed files with 119 additions and 6 deletions

View File

@@ -5,11 +5,12 @@ import (
"encoding/xml"
"errors"
"fmt"
"github.com/google/uuid"
"gosrc.io/xmpp/stanza"
"strings"
"testing"
"time"
"github.com/google/uuid"
"gosrc.io/xmpp/stanza"
)
// Tests are ran in parallel, so each test creating a server must use a different port so we do not get any
@@ -129,7 +130,7 @@ func TestSendIq(t *testing.T) {
//Connecting to a mock server, initialized with given port and handler function
c, m := mockComponentConnection(t, testSendIqPort, h)
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
iqReq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeGet, From: "test1@localhost/mremond-mbp", To: defaultServerName, Id: defaultStreamID, Lang: "en"})
disco := iqReq.DiscoInfo()
iqReq.Payload = disco
@@ -158,6 +159,7 @@ func TestSendIq(t *testing.T) {
case <-time.After(defaultChannelTimeout):
t.Errorf("The mock server failed to finish its job !")
}
cancel()
}
// Checking that error handling is done properly client side when an invalid IQ is sent and the server responds in kind.
@@ -170,7 +172,7 @@ func TestSendIqFail(t *testing.T) {
//Connecting to a mock server, initialized with given port and handler function
c, m := mockComponentConnection(t, testSendIqFailPort, h)
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
iqReq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeGet, From: "test1@localhost/mremond-mbp", To: defaultServerName, Id: defaultStreamID, Lang: "en"})
// Removing the id to make the stanza invalid. The IQ constructor makes a random one if none is specified
@@ -204,6 +206,7 @@ func TestSendIqFail(t *testing.T) {
case <-time.After(defaultChannelTimeout):
t.Errorf("The mock server failed to finish its job !")
}
cancel()
}
// Tests sending raw xml to the mock server.