Skip to content

Commit

Permalink
Fix versions libs. Struvt empty
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 10, 2019
1 parent 0c10cfc commit be49dd7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion websocket/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewAuth(key, secret string) *AuthClient {
parameters: params,
listener: make(chan interface{}),
terminal: false,
shutdown: nil,
shutdown: make(chan struct{}),
asynchronous: nil,
heartbeat: time.Now().Add(params.HeartbeatTimeout),
hbChannel: make(chan error),
Expand Down
16 changes: 9 additions & 7 deletions websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type Client struct {
// connection & operational behavior
parameters *Parameters

// close signal sent to user on shutdown
shutdown chan bool
// channel to stop all routines
shutdown chan struct{}

// downstream listener channel to deliver API objects
listener chan interface{}
Expand Down Expand Up @@ -76,7 +76,7 @@ func New() *Client {
parameters: params,
listener: make(chan interface{}),
terminal: false,
shutdown: nil,
shutdown: make(chan struct{}),
asynchronous: nil,
heartbeat: time.Now().Add(params.HeartbeatTimeout),
hbChannel: make(chan error),
Expand All @@ -98,7 +98,7 @@ func NewSandbox() *Client {
parameters: params,
listener: make(chan interface{}),
terminal: false,
shutdown: nil,
shutdown: make(chan struct{}),
asynchronous: nil,
heartbeat: time.Now().Add(params.HeartbeatTimeout),
hbChannel: make(chan error),
Expand Down Expand Up @@ -181,9 +181,8 @@ func (c *Client) dumpParams() {
func (c *Client) reset() {
if c.asynchronous == nil {
c.asynchronous = c.asyncFactory.Create()
c.init = true
}
c.init = true

c.updateHeartbeat()

go c.listenDisconnect()
Expand Down Expand Up @@ -284,7 +283,10 @@ func (c *Client) close(e error) {
}
close(c.listener)
}
close(c.shutdown)

if c.shutdown != nil {
close(c.shutdown)
}
}

func (c *Client) closeAsyncAndWait(t time.Duration) {
Expand Down
58 changes: 39 additions & 19 deletions websocket/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ func TestClient_SubscribeTicker(t *testing.T) {
func TestClient_close(t *testing.T) {
type fields struct {
listenerIsNil bool
shutdownIsNil bool
}
type args struct {
e error
Expand All @@ -839,39 +840,58 @@ func TestClient_close(t *testing.T) {
args: args{
e: ErrSomething,
},
fields: fields{},
},
{
name: "Close without error",
args: args{
e: nil,
},
fields: fields{},
},
{
name: "Close with nil listener",
args: args{
e: nil,
},
fields: fields{
listenerIsNil: false,
listenerIsNil: true,
},
},
{
name: "Close without error",
name: "Close with nil shutdown",
args: args{
e: nil,
},
fields: fields{
listenerIsNil: false,
shutdownIsNil: true,
},
},
{
name: "Close with nil listener",
name: "Close with nil both channels",
args: args{
e: nil,
},
fields: fields{
shutdownIsNil: true,
listenerIsNil: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Client{
shutdown: make(chan bool),
c := &Client{}
if !tt.fields.shutdownIsNil {
c.shutdown = make(chan struct{})
}
if !tt.fields.listenerIsNil {
c.listener = make(chan interface{})

go func() {
<-c.listener
}()
}
c.listener = make(chan interface{})

go func() {
<-c.listener
}()
c.close(tt.args.e)
})
}
Expand Down Expand Up @@ -905,7 +925,7 @@ func TestClient_exit(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
c := &Client{
terminal: false,
shutdown: make(chan bool),
shutdown: make(chan struct{}),
listener: make(chan interface{}),
}
go func() {
Expand Down Expand Up @@ -1077,7 +1097,7 @@ func TestClient_controlHeartbeat(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Client{
shutdown: make(chan bool),
shutdown: make(chan struct{}),
heartbeat: time.Unix(0, 0),
hbChannel: make(chan error),
}
Expand All @@ -1086,7 +1106,7 @@ func TestClient_controlHeartbeat(t *testing.T) {

go func() {
if tt.fields.isShutdown {
c.shutdown <- true
c.shutdown <- struct{}{}
} else {
<-c.hbChannel
}
Expand Down Expand Up @@ -1119,7 +1139,7 @@ func TestClient_listenUpstream(t *testing.T) {
asynchronous: &mockAsynchronous{
Data: make(chan []byte),
},
shutdown: make(chan bool),
shutdown: make(chan struct{}),
hbChannel: make(chan error),
heartbeat: time.Now().Add(time.Hour),
parameters: NewDefaultSandboxParameters(),
Expand All @@ -1130,7 +1150,7 @@ func TestClient_listenUpstream(t *testing.T) {

go func() {
c.asynchronous.(*mockAsynchronous).Data <- tt.fields.data
c.shutdown <- true
c.shutdown <- struct{}{}
}()

time.Sleep(time.Microsecond)
Expand Down Expand Up @@ -1273,7 +1293,7 @@ func TestClient_reconnect(t *testing.T) {
heartbeat: time.Now().Add(time.Hour),
hbChannel: make(chan error),
parameters: NewDefaultSandboxParameters(),
shutdown: make(chan bool),
shutdown: make(chan struct{}),
listener: make(chan interface{}),
subscriptions: tt.fields.subscriptions,
factories: make(map[string]ParseFactory),
Expand Down Expand Up @@ -1325,13 +1345,13 @@ func TestClient_Close(t *testing.T) {
terminal: false,
init: false,
parameters: NewDefaultSandboxParameters(),
shutdown: make(chan bool),
shutdown: make(chan struct{}),
}
c.parameters.ShutdownTimeout = time.Second

go func() {
if tt.fields.isShutdown {
c.shutdown <- true
c.shutdown <- struct{}{}
}
}()

Expand Down Expand Up @@ -1445,7 +1465,7 @@ func TestClient_listenDisconnect(t *testing.T) {
heartbeat: time.Now().Add(time.Hour),
hbChannel: make(chan error),
parameters: NewDefaultSandboxParameters(),
shutdown: make(chan bool),
shutdown: make(chan struct{}),
}
c.parameters.AutoReconnect = false
if tt.fields.isListenHeartbeat {
Expand Down
2 changes: 1 addition & 1 deletion websocket/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/aopoltorzhicky/go_kraken/websocket
go 1.12

require (
github.com/aopoltorzhicky/go_kraken/rest v0.0.1
github.com/aopoltorzhicky/go_kraken/rest v0.0.3
github.com/gorilla/websocket v1.4.1
)
9 changes: 2 additions & 7 deletions websocket/go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
github.com/aopoltorzhicky/go_kraken v0.0.0-20190605153553-ae21135d148e h1:mdF0mUnFpakK8cgJxay0hr5gmKe6/j3aEy+XCxMu6tU=
github.com/aopoltorzhicky/go_kraken/rest v0.0.0-20190605153553-ae21135d148e h1:TbWk0E283N7vcZ3MlUJ4K9GvryVWwDkCIOblKDBgJdk=
github.com/aopoltorzhicky/go_kraken/rest v0.0.0-20190605153553-ae21135d148e/go.mod h1:lJqZhOEiRSssxjeOOhkHhbSMuWykTrU0tRb4Zyy9kPU=
github.com/aopoltorzhicky/go_kraken/rest v0.0.3 h1:oTRp0xqqsq0g83UOu6dCQtbKTk1lZjqtH3TsaDwDt/o=
github.com/aopoltorzhicky/go_kraken/rest v0.0.3/go.mod h1:cen8hPWBicFQ1T4EoseSAkxvCD7zzZYIzxb0OVTHDk0=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs=
github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 h1:vG/gY/PxA3v3l04qxe3tDjXyu3bozii8ulSlIPOYKhI=
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA=

0 comments on commit be49dd7

Please sign in to comment.