diff --git a/client.go b/client.go
index 4d7857e..254a793 100644
--- a/client.go
+++ b/client.go
@@ -20,6 +20,7 @@ type ConnState = uint8
// This is a the list of events happening on the connection that the
// client can be notified about.
const (
+ InitialPresence = ""
StateDisconnected ConnState = iota
StateConnected
StateSessionEstablished
@@ -199,7 +200,7 @@ func (c *Client) Resume(state SMState) error {
//fmt.Fprintf(client.conn, "%s%s", "chat", "Online")
// TODO: Do we always want to send initial presence automatically ?
// Do we need an option to avoid that or do we rely on client to send the presence itself ?
- err = c.sendWithWriter(c.transport, []byte(""))
+ err = c.sendWithWriter(c.transport, []byte(InitialPresence))
return err
}
diff --git a/client_test.go b/client_test.go
index 0caace0..f2b775a 100644
--- a/client_test.go
+++ b/client_test.go
@@ -184,15 +184,15 @@ func TestClient_SendIQ(t *testing.T) {
select {
case <-res: // If the server responds with an IQ, we pass the test
case err := <-errChan: // If the server sends an error, or there is a connection error
- t.Errorf(err.Error())
+ t.Fatal(err.Error())
case <-time.After(defaultChannelTimeout): // If we timeout
- t.Errorf("Failed to receive response, to sent IQ, from mock server")
+ t.Fatal("Failed to receive response, to sent IQ, from mock server")
}
select {
case <-done:
mock.Stop()
case <-time.After(defaultChannelTimeout):
- t.Errorf("The mock server failed to finish its job !")
+ t.Fatal("The mock server failed to finish its job !")
}
}
diff --git a/tcp_server_mock.go b/tcp_server_mock.go
index efdda23..1084cbd 100644
--- a/tcp_server_mock.go
+++ b/tcp_server_mock.go
@@ -120,6 +120,7 @@ func respondToIQ(t *testing.T, c net.Conn) {
recvBuf := make([]byte, 1024)
var iqR stanza.IQ
_, err := c.Read(recvBuf[:]) // recv data
+
if err != nil {
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
t.Errorf("read timeout: %s", err)
@@ -155,11 +156,22 @@ func respondToIQ(t *testing.T, c net.Conn) {
// When a presence stanza is automatically sent (right now it's the case in the client), we may want to discard it
// and test further stanzas.
func discardPresence(t *testing.T, c net.Conn) {
- decoder := xml.NewDecoder(c)
c.SetDeadline(time.Now().Add(defaultTimeout))
defer c.SetDeadline(time.Time{})
var presenceStz stanza.Presence
- err := decoder.Decode(&presenceStz)
+
+ recvBuf := make([]byte, len(InitialPresence))
+ _, err := c.Read(recvBuf[:]) // recv data
+
+ if err != nil {
+ if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
+ t.Errorf("read timeout: %s", err)
+ } else {
+ t.Errorf("read error: %s", err)
+ }
+ }
+ xml.Unmarshal(recvBuf, &presenceStz)
+
if err != nil {
t.Errorf("Expected presence but this happened : %s", err.Error())
}