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 new integration test cases to test the autoconnect feature.
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientReqDisconnNoAutoconn tests disconnected error when trying to send a request | ||
// while the server is unreachable and autoconn is disabled | ||
func TestClientReqDisconnNoAutoconn(t *testing.T) { | ||
// Initialize client | ||
client := wwrclt.NewClient( | ||
"127.0.0.1:65000", | ||
wwrclt.Options{ | ||
Autoconnect: wwrclt.OptDisabled, | ||
ReconnectionInterval: 5 * time.Millisecond, | ||
DefaultRequestTimeout: 50 * time.Millisecond, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
_, err := client.Request("", wwr.Payload{Data: []byte("testdata")}) | ||
if _, isDisconnErr := err.(wwr.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,32 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientReqDisconnTimeout tests autoconnect timeout when the server is unreachable | ||
func TestClientReqDisconnTimeout(t *testing.T) { | ||
// Initialize client | ||
client := wwrclt.NewClient( | ||
"127.0.0.1:65000", | ||
wwrclt.Options{ | ||
ReconnectionInterval: 5 * time.Millisecond, | ||
DefaultRequestTimeout: 50 * time.Millisecond, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
_, err := client.Request("", wwr.Payload{Data: []byte("testdata")}) | ||
if _, isReqTimeoutErr := err.(wwr.ReqTimeoutErr); !isReqTimeoutErr { | ||
t.Fatalf( | ||
"Expected request timeout 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,34 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientRestSessDisconnNoAutoconn tests disconnected error when trying to manually | ||
// restore the session while the server is unreachable and autoconn is disabled | ||
func TestClientRestSessDisconnNoAutoconn(t *testing.T) { | ||
// Initialize client | ||
client := wwrclt.NewClient( | ||
"127.0.0.1:65000", | ||
wwrclt.Options{ | ||
Autoconnect: wwrclt.OptDisabled, | ||
ReconnectionInterval: 5 * time.Millisecond, | ||
DefaultRequestTimeout: 50 * time.Millisecond, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
err := client.RestoreSession([]byte("inexistentkey")) | ||
if _, isDisconnErr := err.(wwr.DisconnectedErr); !isDisconnErr { | ||
t.Fatalf( | ||
"Expected disconnected error 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,32 @@ | ||
package test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
wwr "github.com/qbeon/webwire-go" | ||
wwrclt "github.com/qbeon/webwire-go/client" | ||
) | ||
|
||
// TestClientRestSessDisconnTimeout tests autoconnect timeout when the server is unreachable | ||
func TestClientRestSessDisconnTimeout(t *testing.T) { | ||
// Initialize client | ||
client := wwrclt.NewClient( | ||
"127.0.0.1:65000", | ||
wwrclt.Options{ | ||
ReconnectionInterval: 5 * time.Millisecond, | ||
DefaultRequestTimeout: 50 * time.Millisecond, | ||
}, | ||
) | ||
|
||
// Send request and await reply | ||
err := client.RestoreSession([]byte("inexistentkey")) | ||
if _, isReqTimeoutErr := err.(wwr.ReqTimeoutErr); !isReqTimeoutErr { | ||
t.Fatalf( | ||
"Expected request timeout error, got: %s | %s", | ||
reflect.TypeOf(err), | ||
err, | ||
) | ||
} | ||
} |