Skip to content

Commit

Permalink
Remove unused return values (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Dec 29, 2019
1 parent bd125da commit 194563f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func TestProtocolViolation(t *testing.T) {
go func() {
if _, err := cli.Connect(ctx, "cli"); err != nil {
if ctx.Err() == nil {
t.Fatalf("Unexpected error: '%v'", err)
t.Errorf("Unexpected error: '%v'", err)
cancel()
}
}
if cli.connState.String() != "Active" {
Expand Down
12 changes: 7 additions & 5 deletions connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,21 @@ func TestConnect_Error(t *testing.T) {
ca, cb := net.Pipe()
cli := &BaseClient{Transport: cb}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

go func() {
if _, err := ca.Read(make([]byte, 100)); err != nil {
t.Fatalf("Unexpected error: '%v'", err)
t.Errorf("Unexpected error: '%v'", err)
cancel()
}

// Send CONNACK.
if _, err := ca.Write(c.response); err != nil {
t.Fatalf("Unexpected error: '%v'", err)
t.Errorf("Unexpected error: '%v'", err)
cancel()
}
}()

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := cli.Connect(ctx, "cli")
if err == nil {
t.Fatal("Error is not returned on connection refuse")
Expand Down
6 changes: 4 additions & 2 deletions reconnclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ func TestReconnectClient_DefaultOptions(t *testing.T) {
t.Fatalf("Unexpected error: '%v'", err)
}
cancel()
_, err = cli.Connect(ctx,
if _, err = cli.Connect(ctx,
"ReconnectClient",
WithKeepAlive(uint16(keepAlive)),
)
); err != context.Canceled {
t.Fatalf("Expected error: '%v', got: '%v'", context.Canceled, err)
}
reconnCli := cli.(*reconnectClient)
if int(reconnCli.options.Timeout/time.Second) != keepAlive {
t.Errorf("Default Timeout should be same as KeepAlice, expected: %d, got %d",
Expand Down
14 changes: 5 additions & 9 deletions retryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func (c *RetryClient) Handle(handler Handler) {
}

// Publish tries to publish the message and immediately return nil.
// If it is not acknowledged to be published, the message will be queued and
// retried on the next connection.
// If it is not acknowledged to be published, the message will be queued.
func (c *RetryClient) Publish(ctx context.Context, message *Message) error {
go func() {
c.mu.Lock()
Expand All @@ -53,8 +52,7 @@ func (c *RetryClient) Publish(ctx context.Context, message *Message) error {
}

// Subscribe tries to subscribe the topic and immediately return nil.
// If it is not acknowledged to be subscribed, the request will be queued and
// retried on the next connection.
// If it is not acknowledged to be subscribed, the request will be queued.
func (c *RetryClient) Subscribe(ctx context.Context, subs ...Subscription) error {
go func() {
c.mu.Lock()
Expand Down Expand Up @@ -131,7 +129,7 @@ func (c *RetryClient) Ping(ctx context.Context) error {
}

// SetClient sets the new Client.
// If there are any queued messages, retry to publish them.
// Call Retry() and Resubscribe() to process queued messages and subscriptions.
func (c *RetryClient) SetClient(ctx context.Context, cli Client) {
c.mu.Lock()
defer c.mu.Unlock()
Expand All @@ -151,7 +149,7 @@ func (c *RetryClient) Connect(ctx context.Context, clientID string, opts ...Conn
}

// Resubscribe subscribes all established subscriptions.
func (c *RetryClient) Resubscribe(ctx context.Context) error {
func (c *RetryClient) Resubscribe(ctx context.Context) {
c.muQueue.Lock()
oldSubEstablished := append([][]Subscription{}, c.subEstablished...)
c.subEstablished = nil
Expand All @@ -165,11 +163,10 @@ func (c *RetryClient) Resubscribe(ctx context.Context) error {
c.subscribe(ctx, true, cli, sub...)
}
}
return nil
}

// Retry all queued publish/subscribe requests.
func (c *RetryClient) Retry(ctx context.Context) error {
func (c *RetryClient) Retry(ctx context.Context) {
c.mu.Lock()
cli := c.Client
c.mu.Unlock()
Expand All @@ -190,5 +187,4 @@ func (c *RetryClient) Retry(ctx context.Context) error {
c.publish(ctx, true, cli, msg)
}
}()
return nil
}
4 changes: 3 additions & 1 deletion serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ func TestRemainingLengthParse(t *testing.T) {
go func() {
if _, err := cli.Connect(ctx, "cli"); err != nil {
if ctx.Err() == nil {
t.Fatalf("Unexpected error: '%v'", err)
t.Errorf("Unexpected error: '%v'", err)
cancel()
}
}
if cli.connState.String() != "Active" {
t.Errorf("State after Connect must be 'Active', but is '%s'", cli.connState)
cancel()
}
close(connected)
}()
Expand Down

0 comments on commit 194563f

Please sign in to comment.