MCPcopy
hub / github.com/IBM/sarama / expectResultsWithTimeout

Function expectResultsWithTimeout

async_producer_test.go:23–57  ·  view source on GitHub ↗
(t *testing.T, p AsyncProducer, successCount, errorCount int, timeout time.Duration)

Source from the content-addressed store, hash-verified

21)
22
23func expectResultsWithTimeout(t *testing.T, p AsyncProducer, successCount, errorCount int, timeout time.Duration) {
24 t.Helper()
25 expect := successCount + errorCount
26 defer func() {
27 if successCount != 0 || errorCount != 0 {
28 t.Error("Unexpected successes", successCount, "or errors", errorCount)
29 }
30 }()
31 timer := time.NewTimer(timeout)
32 defer timer.Stop()
33 for expect > 0 {
34 select {
35 case <-timer.C:
36 return
37 case msg := <-p.Errors():
38 if msg.Msg.flags != 0 {
39 t.Error("Message had flags set")
40 }
41 errorCount--
42 expect--
43 if errorCount < 0 {
44 t.Error(msg.Err)
45 }
46 case msg := <-p.Successes():
47 if msg.flags != 0 {
48 t.Error("Message had flags set")
49 }
50 successCount--
51 expect--
52 if successCount < 0 {
53 t.Error("Too many successes")
54 }
55 }
56 }
57}
58
59func expectResults(t *testing.T, p AsyncProducer, successCount, errorCount int) {
60 expectResultsWithTimeout(t, p, successCount, errorCount, 5*time.Minute)

Callers 3

expectResultsFunction · 0.85

Calls 5

HelperMethod · 0.80
StopMethod · 0.80
ErrorMethod · 0.65
ErrorsMethod · 0.65
SuccessesMethod · 0.65

Tested by

no test coverage detected