Skip to content

Commit

Permalink
revert changes to consumer group invalid return values
Browse files Browse the repository at this point in the history
  • Loading branch information
jnjackins committed Oct 25, 2018
1 parent 3306e5a commit 48324a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,10 +1368,11 @@ func (r *Reader) ReadLag(ctx context.Context) (lag int64, err error) {
return
}

// Offset returns the current offset of the reader.
// Offset returns the current absolute offset of the reader, or -1
// if r is backed by a consumer group
func (r *Reader) Offset() int64 {
if r.useConsumerGroup() {
return 0
return -1
}

r.mutex.Lock()
Expand All @@ -1386,7 +1387,7 @@ func (r *Reader) Offset() int64 {
// Lag returns the lag of the last message returned by ReadMessage.
func (r *Reader) Lag() int64 {
if r.useConsumerGroup() {
return 0
return -1
}

r.mutex.Lock()
Expand Down
8 changes: 4 additions & 4 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,15 @@ func TestReaderSetOffsetWhenConsumerGroupsEnabled(t *testing.T) {

func TestReaderOffsetWhenConsumerGroupsEnabled(t *testing.T) {
r := &Reader{config: ReaderConfig{GroupID: "not-zero"}}
if offset := r.Offset(); offset != 0 {
t.Fatalf("expected 0; got %v", offset)
if offset := r.Offset(); offset != -1 {
t.Fatalf("expected -1; got %v", offset)
}
}

func TestReaderLagWhenConsumerGroupsEnabled(t *testing.T) {
r := &Reader{config: ReaderConfig{GroupID: "not-zero"}}
if offset := r.Lag(); offset != 0 {
t.Fatalf("expected 0; got %v", offset)
if offset := r.Lag(); offset != -1 {
t.Fatalf("expected -1; got %v", offset)
}
}

Expand Down

0 comments on commit 48324a3

Please sign in to comment.