Skip to content

Commit ff8d238

Browse files
committed
Review comments #1.
1 parent 33497a3 commit ff8d238

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

xds/internal/resolver/xds_resolver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (t *testClientConn) ParseServiceConfig(jsonSC string) *serviceconfig.ParseR
7777

7878
func newTestClientConn() *testClientConn {
7979
return &testClientConn{
80-
stateCh: channel.NewChanWithTimeout(),
81-
errorCh: channel.NewChanWithTimeout(),
80+
stateCh: channel.NewChan(),
81+
errorCh: channel.NewChan(),
8282
}
8383
}
8484

xds/internal/testutils/channel/channel.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,17 @@ const (
3939
// WithTimeout wraps a generic channel and provides a timed receive operation.
4040
type WithTimeout struct {
4141
ch chan interface{}
42-
// RecvTimeout is the timeout duration for receive operations on the
43-
// underlying channel.
44-
RecvTimeout time.Duration
4542
}
4643

4744
// Send sends value on the underlying channel.
4845
func (cwt *WithTimeout) Send(value interface{}) {
4946
cwt.ch <- value
5047
}
5148

52-
// Receive returns the value received on the underlying channel, or
53-
// ErrRecvTimeout if the operation times out.
54-
func (cwt *WithTimeout) Receive() (interface{}, error) {
55-
timer := time.NewTimer(cwt.RecvTimeout)
49+
// TimedReceive returns the value received on the underlying channel, or
50+
// ErrRecvTimeout if timeout amount of time elapsed.
51+
func (cwt *WithTimeout) TimedReceive(timeout time.Duration) (interface{}, error) {
52+
timer := time.NewTimer(timeout)
5653
select {
5754
case <-timer.C:
5855
return nil, ErrRecvTimeout
@@ -62,15 +59,13 @@ func (cwt *WithTimeout) Receive() (interface{}, error) {
6259
}
6360
}
6461

65-
// NewChanWithTimeout makes a WithTimeout channel using the defaults.
66-
func NewChanWithTimeout() *WithTimeout {
67-
return NewChan(DefaultRecvTimeout, DefaultBufferSize)
62+
// Receive returns the value received on the underlying channel, or
63+
// ErrRecvTimeout if DefaultRecvTimeout amount of time elapses.
64+
func (cwt *WithTimeout) Receive() (interface{}, error) {
65+
return cwt.TimedReceive(DefaultRecvTimeout)
6866
}
6967

70-
// NewChan makes a WithTimeout channel using the provided timeout and bufSize.
71-
func NewChan(timeout time.Duration, bufSize int) *WithTimeout {
72-
return &WithTimeout{
73-
ch: make(chan interface{}, bufSize),
74-
RecvTimeout: timeout,
75-
}
68+
// NewChan returns a new WithTimeout channel.
69+
func NewChan() *WithTimeout {
70+
return &WithTimeout{ch: make(chan interface{}, DefaultBufferSize)}
7671
}

xds/internal/testutils/fakeclient/xds.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func (xdsC *XDS) Close() {
6363
// NewXDS returns a new fake xds client.
6464
func NewXDS() *XDS {
6565
return &XDS{
66-
suWatchCh: channel.NewChanWithTimeout(),
67-
closeCh: channel.NewChanWithTimeout(),
68-
suCancelCh: channel.NewChanWithTimeout(),
66+
suWatchCh: channel.NewChan(),
67+
closeCh: channel.NewChan(),
68+
suCancelCh: channel.NewChan(),
6969
}
7070
}

0 commit comments

Comments
 (0)