This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client disconnected error type and add integration test cases to test client.Request, client.Signal and client.RestoreSession on disconnected client.
- Loading branch information
Showing
7 changed files
with
121 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package client | ||
|
||
// DisconnectedErr is an error type indicating that the client isn't connected to the server | ||
type DisconnectedErr struct{} | ||
|
||
func (err DisconnectedErr) Error() string { | ||
return "Client is disconnected" | ||
} |
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,36 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientRestoreSessionDisconnected tests manual session restoration on disconnected client | ||
func TestClientRestoreSessionDisconnected(t *testing.T) { | ||
// Initialize webwire server | ||
_, addr := setupServer( | ||
t, | ||
wwr.ServerOptions{}, | ||
) | ||
|
||
// Initialize client | ||
client := wwrclt.NewClient( | ||
addr, | ||
wwrclt.Options{ | ||
DefaultRequestTimeout: 2 * time.Second, | ||
}, | ||
) | ||
|
||
err := client.RestoreSession([]byte("somekey")) | ||
if _, isDisconnErr := err.(wwrclt.DisconnectedErr); !isDisconnErr { | ||
t.Fatalf( | ||
"Expected disconnected error, got: %s | %s", | ||
reflect.TypeOf(err), | ||
err, | ||
) | ||
} | ||
} |
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,37 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientSignalDisconnected tests sending signals on disconnected clients | ||
func TestClientSignalDisconnected(t *testing.T) { | ||
// Initialize webwire server given only the request | ||
_, addr := setupServer( | ||
t, | ||
wwr.ServerOptions{}, | ||
) | ||
|
||
// Initialize client | ||
client := wwrclt.NewClient( | ||
addr, | ||
wwrclt.Options{ | ||
DefaultRequestTimeout: 2 * time.Second, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
err := client.Signal("", wwr.Payload{Data: []byte("testdata")}) | ||
if _, isDisconnErr := err.(wwrclt.DisconnectedErr); !isDisconnErr { | ||
t.Fatalf( | ||
"Expected disconnected error, got: %s | %s", | ||
reflect.TypeOf(err), | ||
err, | ||
) | ||
} | ||
} |
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,37 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientRequestDisconnected tests sending requests on disconnected clients | ||
func TestClientRequestDisconnected(t *testing.T) { | ||
// Initialize webwire server given only the request | ||
_, addr := setupServer( | ||
t, | ||
wwr.ServerOptions{}, | ||
) | ||
|
||
// Initialize client | ||
client := wwrclt.NewClient( | ||
addr, | ||
wwrclt.Options{ | ||
DefaultRequestTimeout: 2 * time.Second, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
_, err := client.Request("", wwr.Payload{Data: []byte("testdata")}) | ||
if _, isDisconnErr := err.(wwrclt.DisconnectedErr); !isDisconnErr { | ||
t.Fatalf( | ||
"Expected disconnected error, got: %s | %s", | ||
reflect.TypeOf(err), | ||
err, | ||
) | ||
} | ||
} |