Skip to content

Commit d7717cf

Browse files
committed
Adjusting compose and test to be fair
1 parent 693d6eb commit d7717cf

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ services:
4242
container_name: kafka
4343
ports:
4444
- 9092:9092
45+
environment:
46+
KAFKA_NODE_ID: 1
47+
KAFKA_PROCESS_ROLES: broker,controller
48+
KAFKA_LISTENERS: LOCAL://0.0.0.0:9092,DOCKER://kafka:9093,CONTROLLER://localhost:9094
49+
KAFKA_ADVERTISED_LISTENERS: LOCAL://localhost:9092,DOCKER://kafka:9093
50+
KAFKA_INTER_BROKER_LISTENER_NAME: LOCAL
51+
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
52+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,LOCAL:PLAINTEXT,DOCKER:PLAINTEXT
53+
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9094
54+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
55+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
56+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
57+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
58+
KAFKA_NUM_PARTITIONS: 1
59+
restart: on-failure
60+
61+
kafka-ui:
62+
container_name: kafka-ui
63+
image: provectuslabs/kafka-ui:latest
64+
ports:
65+
- 8080:8080
66+
depends_on:
67+
- kafka
68+
environment:
69+
DYNAMIC_CONFIG_ENABLED: 'true'
70+
KAFKA_CLUSTERS_0_NAME: Local
71+
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9093
4572
restart: on-failure
4673

4774
volumes:

packages/kafka/lib/test.spec.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
import { randomUUID } from 'node:crypto'
12
import { once } from 'node:events'
23
import { waitAndRetry } from '@lokalise/universal-ts-utils/node'
3-
import { KafkaConsumer, type Message, Producer, features, librdkafkaVersion } from 'node-rdkafka'
4+
import { KafkaConsumer, type Message, Producer } from 'node-rdkafka'
45

56
// TODO: to be removed once we have proper tests
67
describe('Test', () => {
7-
it('should use node-rdkafka', () => {
8-
expect(features).toBeDefined()
9-
expect(librdkafkaVersion).toBeDefined()
10-
})
11-
12-
it('should send and receive a message', { timeout: 10000 }, async () => {
8+
it('should send and receive a message', async () => {
139
// Given
1410
const brokers = 'localhost:9092'
1511
// Use a fresh, unique topic per run to avoid stale state
@@ -26,13 +22,11 @@ describe('Test', () => {
2622
producer.connect()
2723
await once(producer, 'ready')
2824

29-
// Create a consumer with a unique group and disable auto-commit for fresh offsets
3025
const consumer = new KafkaConsumer(
3126
{
32-
'group.id': 'test-group',
27+
'group.id': randomUUID(),
3328
'metadata.broker.list': brokers,
3429
'allow.auto.create.topics': true,
35-
'enable.auto.commit': false,
3630
},
3731
{ 'auto.offset.reset': 'earliest' },
3832
)
@@ -56,7 +50,7 @@ describe('Test', () => {
5650
producer.flush()
5751

5852
// Then
59-
await waitAndRetry(() => receivedMessages.length > 0, 10, 800)
53+
await waitAndRetry(() => receivedMessages.length > 0, 10, 1000)
6054
expect(receivedMessages).toHaveLength(1)
6155
expect(receivedMessages[0]?.value?.toString()).toBe(messageValue)
6256

0 commit comments

Comments
 (0)