Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
Add new integration test cases
Browse files Browse the repository at this point in the history
Add new integration test cases to test the autoconnect feature.
  • Loading branch information
romshark committed Mar 21, 2018
1 parent aad55e7 commit e996bb6
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/clientReqDisconnNoAutoconn_test.go
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,
)
}
}
32 changes: 32 additions & 0 deletions test/clientReqDisconnTimeout_test.go
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,
)
}
}
34 changes: 34 additions & 0 deletions test/clientRestSessDisconnNoAutoconn_test.go
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,
)
}
}
32 changes: 32 additions & 0 deletions test/clientRestSessDisconnTimeout_test.go
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,
)
}
}

0 comments on commit e996bb6

Please sign in to comment.