Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(cdp): stop deleting shared kafka topics in e2e tests (#64531)

Paweł Ledwońd11b0732adc3
diff --git a/nodejs/src/cdp/cdp-e2e.test.ts b/nodejs/src/cdp/cdp-e2e.test.ts
index e4cdb48d9c90..c1cf1f201f81 100644
--- a/nodejs/src/cdp/cdp-e2e.test.ts
+++ b/nodejs/src/cdp/cdp-e2e.test.ts
@@ -5,7 +5,7 @@ import { KafkaProducerObserver } from '~/tests/helpers/mocks/producer.spy'
import { createCdpConsumerDeps } from '~/tests/helpers/cdp'
import { waitForExpect } from '~/tests/helpers/expectations'
-import { resetKafka } from '~/tests/helpers/kafka'
+import { TEST_KAFKA_TOPICS, ensureKafkaTopics } from '~/tests/helpers/kafka'
import { forSnapshot } from '~/tests/helpers/snapshots'
import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql'
@@ -57,7 +57,7 @@ describe('CDP Consumer loop', () => {
return ActualKafkaProducerWrapper.create(...args)
})
- await resetKafka()
+ await ensureKafkaTopics(TEST_KAFKA_TOPICS)
await resetTestDatabase()
hub = await createHub()
diff --git a/nodejs/src/cdp/rerun/rerun-e2e.test.ts b/nodejs/src/cdp/rerun/rerun-e2e.test.ts
index 16fe1894bced..cd2c4a5cc5db 100644
--- a/nodejs/src/cdp/rerun/rerun-e2e.test.ts
+++ b/nodejs/src/cdp/rerun/rerun-e2e.test.ts
@@ -9,11 +9,11 @@ import { Pool } from 'pg'
import { createCdpConsumerDeps } from '~/tests/helpers/cdp'
import { Clickhouse } from '~/tests/helpers/clickhouse'
import { waitForExpect } from '~/tests/helpers/expectations'
-import { ensureKafkaTopics, resetKafka } from '~/tests/helpers/kafka'
+import { TEST_KAFKA_TOPICS, ensureKafkaTopics } from '~/tests/helpers/kafka'
import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql'
import { PersonReadRepository } from '~/worker/ingestion/persons/repositories/person-repository'
-import { KAFKA_HOG_INVOCATION_RESULTS, KAFKA_INGESTION_WARNINGS } from '../../config/kafka-topics'
+import { KAFKA_HOG_INVOCATION_RESULTS } from '../../config/kafka-topics'
import { KafkaProducerWrapper } from '../../kafka/producer'
import { Hub, Team } from '../../types'
import { closeHub, createHub } from '../../utils/db/hub'
@@ -45,11 +45,10 @@ interface PersistedRow {
}
/**
- * Probe the ClickHouse Kafka MV for our topic in particular. resetKafka()
- * deletes and recreates the topic, which forces the MV's internal consumer to
- * reconnect; with auto.offset.reset=latest, anything produced before the
- * reconnect is silently dropped. Send probe rows until one lands in CH so we
- * know the MV is live.
+ * Probe the ClickHouse Kafka MV for our topic in particular. With
+ * auto.offset.reset=latest, anything produced before the MV's internal consumer
+ * has attached is silently dropped. Send probe rows until one lands in CH so we
+ * know the MV is live before the test produces real rows.
*/
const waitForHogInvocationResultsMvReady = async (clickhouse: Clickhouse): Promise<void> => {
const producer = await ActualKafkaProducerWrapper.create(undefined)
@@ -149,10 +148,10 @@ describe('CDP hog invocation rerun e2e', () => {
// real producer to observe via KafkaProducerObserver.
MockKafkaProducerWrapper.create = jest.fn((...args: any[]) => ActualKafkaProducerWrapper.create(...args))
- await resetKafka()
- // resetKafka does not include KAFKA_HOG_INVOCATION_RESULTS — add it so the
- // ClickHouse Kafka engine consumer can attach.
- await ensureKafkaTopics([KAFKA_HOG_INVOCATION_RESULTS, KAFKA_INGESTION_WARNINGS])
+ // Ensure all topics exist (idempotently, without deleting) so the ClickHouse
+ // Kafka engine consumers keep their connections. Includes KAFKA_HOG_INVOCATION_RESULTS,
+ // which this test's MV needs but the shared set does not cover.
+ await ensureKafkaTopics([...TEST_KAFKA_TOPICS, KAFKA_HOG_INVOCATION_RESULTS])
await clickhouse.truncate('hog_invocation_results_data')
await waitForHogInvocationResultsMvReady(clickhouse)
await resetTestDatabase()
diff --git a/nodejs/src/cdp/workflows-e2e.test.ts b/nodejs/src/cdp/workflows-e2e.test.ts
index fe5df4a66453..ee86d6735c3e 100644
--- a/nodejs/src/cdp/workflows-e2e.test.ts
+++ b/nodejs/src/cdp/workflows-e2e.test.ts
@@ -21,7 +21,7 @@ import { register } from 'prom-client'
import { createCdpConsumerDeps } from '~/tests/helpers/cdp'
import { waitForExpect } from '~/tests/helpers/expectations'
-import { resetKafka } from '~/tests/helpers/kafka'
+import { TEST_KAFKA_TOPICS, ensureKafkaTopics } from '~/tests/helpers/kafka'
import { getFirstTeam, resetTestDatabase } from '~/tests/helpers/sql'
import { KAFKA_APP_METRICS_2, KAFKA_LOG_ENTRIES } from '../../src/config/kafka-topics'
@@ -95,7 +95,7 @@ describe.each(['postgres-v2' as const, 'postgres' as const])('Workflows E2E (%s)
return ActualKafkaProducerWrapper.create(...args)
})
- await resetKafka()
+ await ensureKafkaTopics(TEST_KAFKA_TOPICS)
await resetTestDatabase()
await cyclotronPool.query('DELETE FROM cyclotron_jobs')
@@ -1361,7 +1361,7 @@ describe('Workflows E2E (email queue)', () => {
return ActualKafkaProducerWrapper.create(...args)
})
- await resetKafka()
+ await ensureKafkaTopics(TEST_KAFKA_TOPICS)
await resetTestDatabase()
await cyclotronPool.query('DELETE FROM cyclotron_jobs')