Skip to content

Commit

Permalink
Trying to fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawscott committed Jul 14, 2020
1 parent 6e17e74 commit f8a4447
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions test/integration/kayrock/timestamp_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule KafkaEx.KayrockTimestampTest do
test "log with append time - v0", %{client: client} do
topic = "test_log_append_timestamp_#{:rand.uniform(2_000_000)}"

{:ok, topic} =
{:ok, ^topic} =
TestHelper.ensure_append_timestamp_topic(
client,
topic
Expand Down Expand Up @@ -148,7 +148,7 @@ defmodule KafkaEx.KayrockTimestampTest do
test "log with append time - v3", %{client: client} do
topic = "test_log_append_timestamp_#{:rand.uniform(2_000_000)}"

{:ok, topic} =
{:ok, ^topic} =
TestHelper.ensure_append_timestamp_topic(
client,
topic
Expand Down Expand Up @@ -186,7 +186,7 @@ defmodule KafkaEx.KayrockTimestampTest do
test "log with append time - v5", %{client: client} do
topic = "test_log_append_timestamp_#{:rand.uniform(2_000_000)}"

{:ok, topic} =
{:ok, ^topic} =
TestHelper.ensure_append_timestamp_topic(
client,
topic
Expand Down
13 changes: 9 additions & 4 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule TestHelper do
topic_errors: [%{error_code: error_code}]
}} = resp

wait_for_topic_to_appear(client, topic_name)
wait_for_topic_to_appear(client, topic_name)

if error_code in [0, 36] do
{:ok, topic_name}
Expand All @@ -128,15 +128,20 @@ defmodule TestHelper do

defp wait_for_topic_to_appear(_client, _topic_name, attempts \\ 10)

defp wait_for_topic_to_appear(_client, _topic_name, attempts) when attempts <= 0 do
defp wait_for_topic_to_appear(_client, _topic_name, attempts)
when attempts <= 0 do
raise "Timeout while waiting for topic to appear"
end

defp wait_for_topic_to_appear(client, topic_name, attempts) do
{:ok, %{topic_metadata: topic_metadata}} =
Client.send_request(client, %Kayrock.Metadata.V0.Request{}, NodeSelector.controller())
Client.send_request(
client,
%Kayrock.Metadata.V0.Request{},
NodeSelector.topic_partition(topic_name, 0)
)

topics = topic_metadata |> Enum.map(&(&1.topic))
topics = topic_metadata |> Enum.map(& &1.topic)

unless topic_name in topics do
wait_for_topic_to_appear(client, topic_name, attempts - 1)
Expand Down

0 comments on commit f8a4447

Please sign in to comment.