Skip to content

Commit

Permalink
Lifecycle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Feb 4, 2017
1 parent 9828f74 commit 4b8f458
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
7 changes: 1 addition & 6 deletions internal/sync/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ package sync

import (
"context"
"errors"

"go.uber.org/atomic"
)

// LifecycleState represents `states` that a lifecycle object can be in.
type LifecycleState int

// ErrAlreadyStopped is returned by WhenRunning to escape early if a lifecycle
// has ended already.
var ErrAlreadyStopped = errors.New("already stopped")

const (
// Idle indicates the Lifecycle hasn't been operated on yet.
Idle LifecycleState = iota
Expand Down Expand Up @@ -127,7 +122,7 @@ func (l *lifecycleOnce) WhenRunning(ctx context.Context) error {
case <-l.startCh:
return nil
case <-l.stopCh:
return ErrAlreadyStopped
return context.DeadlineExceeded
case <-ctx.Done():
return ctx.Err()
}
Expand Down
3 changes: 1 addition & 2 deletions peer/x/peerheap/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"go.uber.org/yarpc/api/peer"
. "go.uber.org/yarpc/api/peer/peertest"
yerrors "go.uber.org/yarpc/internal/errors"
"go.uber.org/yarpc/internal/sync"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestPeerHeapList(t *testing.T) {
StartAction{},
StopAction{},
ChooseAction{
ExpectedErr: sync.ErrAlreadyStopped,
ExpectedErr: context.DeadlineExceeded,
InputContextTimeout: 10 * time.Millisecond,
},
},
Expand Down
2 changes: 1 addition & 1 deletion peer/x/roundrobin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (pl *List) removeFromUnavailablePeers(p peer.Peer) {
// Choose selects the next available peer in the round robin
func (pl *List) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error) {
if err := pl.once.WhenRunning(ctx); err != nil {
return nil, nil, peer.ErrPeerListNotStarted("RoundRobinList")
return nil, nil, err
}

for {
Expand Down
4 changes: 2 additions & 2 deletions peer/x/roundrobin/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ func TestRoundRobinList(t *testing.T) {
peerListActions: []PeerListAction{
UpdateAction{AddedPeerIDs: []string{"1"}},
ChooseAction{
ExpectedErr: peer.ErrPeerListNotStarted("RoundRobinList"),
ExpectedErr: context.DeadlineExceeded,
InputContextTimeout: 10 * time.Millisecond,
},
ChooseAction{
ExpectedErr: peer.ErrPeerListNotStarted("RoundRobinList"),
ExpectedErr: context.DeadlineExceeded,
InputContextTimeout: 10 * time.Millisecond,
},
},
Expand Down

0 comments on commit 4b8f458

Please sign in to comment.