Browse Source

Fix the flakiest producer test

This should fix the last remaining annoyingly-flaky test after all the work
Maxim did on the flaky consumer tests. I hope.
Evan Huus 9 years ago
parent
commit
737294ce64
1 changed files with 7 additions and 4 deletions
  1. 7 4
      async_producer_test.go

+ 7 - 4
async_producer_test.go

@@ -580,20 +580,23 @@ func TestAsyncProducerFlusherRetryCondition(t *testing.T) {
 	prodNotLeader.AddTopicPartition("my_topic", 0, ErrNotLeaderForPartition)
 	leader.Returns(prodNotLeader)
 
+	time.Sleep(50 * time.Millisecond)
+
+	leader.SetHandlerByMap(map[string]MockResponse{
+		"ProduceRequest": newMockProduceResponse(t).
+			SetError("my_topic", 0, ErrNoError),
+	})
+
 	// tell partition 0 to go to that broker again
 	seedBroker.Returns(metadataResponse)
 
 	// succeed this time
-	prodSuccess := new(ProduceResponse)
-	prodSuccess.AddTopicPartition("my_topic", 0, ErrNoError)
-	leader.Returns(prodSuccess)
 	expectResults(t, producer, 5, 0)
 
 	// put five more through
 	for i := 0; i < 5; i++ {
 		producer.Input() <- &ProducerMessage{Topic: "my_topic", Key: nil, Value: StringEncoder(TestMessage), Partition: 0}
 	}
-	leader.Returns(prodSuccess)
 	expectResults(t, producer, 5, 0)
 
 	// shutdown