Skip to content

Commit

Permalink
Extend unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
erni27 committed Apr 14, 2023
1 parent 504f784 commit 12cf912
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/buffer/unbounded.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func (b *Unbounded) Load() {
//
// Upon reading a value from this channel, users are expected to call Load() to
// send the next buffered value onto the channel if there is any.
// If the unbounded buffer is closed, a read channel returned by this method is closed.
//
// If the unbounded buffer is closed, the read channel returned by this method
// is closed.
func (b *Unbounded) Get() <-chan interface{} {
return b.c
}
Expand Down
7 changes: 7 additions & 0 deletions internal/buffer/unbounded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ func (s) TestMultipleWriters(t *testing.T) {
}
}

// TestClose makes sure that the buffer is closed after calling Close().
func (s) TestClose(t *testing.T) {
ub := NewUnbounded()
ub.Close()
if v, ok := <-ub.Get(); ok {
t.Errorf("Unbounded.Get() = %v, want closed channel", v)
}
ub.Put(1)
ub.Load()
if v, ok := <-ub.Get(); ok {
t.Errorf("Unbounded.Get() = %v, want closed channel", v)
}
ub.Close()
if v, ok := <-ub.Get(); ok {
t.Errorf("Unbounded.Get() = %v, want closed channel", v)
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/xdsclient/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (t *Transport) send(ctx context.Context) {
sendNodeProto = false
case u, ok := <-t.adsRequestCh.Get():
if !ok {
// No requests will be sent after the channel is closed.
// No requests will be sent after the unbounded buffer is closed.
return
}
t.adsRequestCh.Load()
Expand Down

0 comments on commit 12cf912

Please sign in to comment.