Skip to content

Commit

Permalink
Check number of attempts in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jnjackins committed Jun 15, 2020
1 parent 55e867e commit 2695e01
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ func TestValidateWriter(t *testing.T) {
}
}

type fakeWriter struct{}
type fakeWriter struct {
attempts int
}

func (f *fakeWriter) messages() chan<- writerMessage {
ch := make(chan writerMessage, 1)

go func() {
for {
msg := <-ch
f.attempts++
msg.res <- &writerError{
err: errors.New("bad attempt"),
}
Expand All @@ -157,20 +160,21 @@ func (f *fakeWriter) messages() chan<- writerMessage {
return ch
}

func (f *fakeWriter) close() {

}
func (f *fakeWriter) close() {}

func testWriterMaxAttemptsErr(t *testing.T) {
const topic = "test-writer-2"
const maxAttempts = 3

var fw fakeWriter

createTopic(t, topic, 1)
w := newTestWriter(WriterConfig{
Topic: topic,
MaxAttempts: 1,
Balancer: &RoundRobin{},
newPartitionWriter: func(p int, config WriterConfig, stats *writerStats) partitionWriter {
return &fakeWriter{}
return &fw
},
})
defer w.Close()
Expand All @@ -186,6 +190,10 @@ func testWriterMaxAttemptsErr(t *testing.T) {
return
}
}

if fw.attempts != maxAttempts {
t.Errorf("got %d attempts, want %d", fw.attempts, maxAttempts)
}
}

func testWriterMaxBytes(t *testing.T) {
Expand Down

0 comments on commit 2695e01

Please sign in to comment.