MCPcopy
hub / github.com/segmentio/kafka-go / testReaderTopicRecreated

Function testReaderTopicRecreated

reader_test.go:1979–1998  ·  view source on GitHub ↗

The current behavior of the Reader is to retry OffsetOutOfRange errors indefinitely, which results in programs hanging in the event of a topic being re-created while a consumer is running. To retain backwards-compatibility, ReaderConfig.OffsetOutOfRangeError is being used to instruct the Reader to r

(t *testing.T, ctx context.Context, r *Reader)

Source from the content-addressed store, hash-verified

1977// ReaderConfig.OffsetOutOfRangeError is being used to instruct the Reader to
1978// return an error in this case instead, allowing callers to react.
1979func testReaderTopicRecreated(t *testing.T, ctx context.Context, r *Reader) {
1980 r.config.OffsetOutOfRangeError = true
1981
1982 topic := r.config.Topic
1983
1984 // add 1 message to the topic
1985 prepareReader(t, ctx, r, makeTestSequence(1)...)
1986
1987 // consume the message (moving the offset from 0 -> 1)
1988 _, err := r.ReadMessage(ctx)
1989 require.NoError(t, err)
1990
1991 // destroy the topic, then recreate it so the offset now becomes 0
1992 deleteTopic(t, topic)
1993 createTopic(t, topic, 1)
1994
1995 // expect an error, since the offset should now be out of range
1996 _, err = r.ReadMessage(ctx)
1997 require.ErrorIs(t, err, OffsetOutOfRange)
1998}

Callers

nothing calls this directly

Calls 5

prepareReaderFunction · 0.85
makeTestSequenceFunction · 0.85
deleteTopicFunction · 0.85
createTopicFunction · 0.85
ReadMessageMethod · 0.45

Tested by

no test coverage detected