Skip to content

Commit

Permalink
Fix CI (#3)
Browse files Browse the repository at this point in the history
* Fix CI

* Fail fast on  unexpected errors

* Remove topic configs

---------

Co-authored-by: Michal Gibowski <[email protected]>
  • Loading branch information
mgibowski and mgibowski-andjaro authored Nov 1, 2023
1 parent 2c43100 commit 42e0076
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
62 changes: 21 additions & 41 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and test

on:
push:
branches: [ master ]
branches: [ master, fix_ci ]
pull_request:
branches: [ master ]

Expand All @@ -11,46 +11,6 @@ jobs:

name: Build and test
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: kafkaesque_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
kafka:
image: wurstmeister/kafka
env:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
ports:
- 9092:9092
depends-on:
- zookeeper
options: >-
--health-cmd "nc -z localhost 9092"
--health-interval 10s
--health-timeout 5s
--health-retries 5
zookeeper:
image: wurstmeister/zookeeper
ports:
- 2181:2181
options: >-
--health-cmd "echo stat | nc localhost 2181 | grep Mode"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
Expand All @@ -63,6 +23,26 @@ jobs:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Start supporting services
run: docker compose --profile with-postgres up -d
- name: Ensure Schema Registry is started
# Copied from: https://github.com/happening-oss/kafka-client/blob/develop/.github/workflows/ci.yml
run: |
# give up after 60 seconds
max_wait_time=60
# Use a loop to check if Schema Registry is ready
start_time=$(date +%s)
until docker compose logs schema-registry | grep -q "started"; do
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge "$max_wait_time" ]; then
echo "Schema Registry did not start within the specified timeout."
exit 1 # Exit the workflow with an error
fi
sleep 5
done
- name: Install dependencies
run: mix deps.get
- name: Setup Database
Expand Down
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
version: '3'
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: kafkaesque_test
ports:
- 5432:5432
profiles: ["with-postgres"]
kafka:
image: confluentinc/cp-kafka:7.5.1
ports:
- 9092:9092
environment:
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:29093
KAFKA_LISTENERS: PLAINTEXT://kafka:29092,CONTROLLER://localhost:29093,PLAINTEXT_HOST://0.0.0.0:9092
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
schema-registry:
image: confluentinc/cp-schema-registry:7.5.1
environment:
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka:29092
SCHEMA_REGISTRY_HOST_NAME: localhost
ports:
- 8081:8081
depends_on:
- kafka
2 changes: 1 addition & 1 deletion test/kafkaesque/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Kafkaesque.IntegrationTest do
assert message.state == :pending

# Could perform some synchronization to avoid sleeping
:timer.sleep(500)
:timer.sleep(1000)

message2 = Repo.reload(message)

Expand Down
30 changes: 7 additions & 23 deletions test/support/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,25 @@ defmodule Kafkaesque.Test.Helpers do
def create_topics() do
topic_configs = [
%{
configs: [
%{
name: "cleanup.policy",
value: "compact"
},
%{
name: "confluent.value.schema.validation",
value: false
}
],
configs: [],
num_partitions: 1,
replication_factor: 1,
assignments: [],
name: "integration_test_topic"
},
%{
configs: [
%{
name: "cleanup.policy",
value: "compact"
},
%{
name: "confluent.value.schema.validation",
value: true
}
],
configs: [],
num_partitions: 1,
replication_factor: 1,
assignments: [],
name: "integration_test_topic_2"
}
]

_ = :brod.create_topics([{"localhost", 9092}], topic_configs, %{timeout: 15_000})

:ok
case :brod.create_topics([{"localhost", 9092}], topic_configs, %{timeout: 15_000}) do
:ok -> :ok
{:error, :topic_already_exists} -> :ok
resp -> raise "Couldn't create topics - :brod.create_topics/3 returned #{inspect(resp)}"
end
end
end

0 comments on commit 42e0076

Please sign in to comment.