diff --git a/posthog/src/main/java/com/posthog/internal/PostHogQueue.kt b/posthog/src/main/java/com/posthog/internal/PostHogQueue.kt index fac0825d..0a02b94e 100644 --- a/posthog/src/main/java/com/posthog/internal/PostHogQueue.kt +++ b/posthog/src/main/java/com/posthog/internal/PostHogQueue.kt @@ -75,7 +75,7 @@ internal class PostHogQueue( dirCreated = true } - val uuid = TimeBasedEpochGenerator.generate() + val uuid = event.uuid ?: TimeBasedEpochGenerator.generate() val file = File(dir, "$uuid.event") synchronized(dequeLock) { deque.add(file) diff --git a/posthog/src/test/java/com/posthog/Utils.kt b/posthog/src/test/java/com/posthog/Utils.kt index eb0b9092..4d8e2662 100644 --- a/posthog/src/test/java/com/posthog/Utils.kt +++ b/posthog/src/test/java/com/posthog/Utils.kt @@ -55,13 +55,16 @@ public val groupProps: Map = mapOf("premium" to true) public val props: Map = mapOf("prop" to "value") public val uuid: UUID = UUID.fromString("8c04e5c1-8f6e-4002-96fd-1804799b6ffe") -public fun generateEvent(eventName: String? = null): PostHogEvent { +public fun generateEvent( + eventName: String? = null, + givenUuuid: UUID? = null, +): PostHogEvent { return PostHogEvent( eventName ?: EVENT, distinctId = DISTINCT_ID, properties = props, timestamp = date, - uuid = uuid, + uuid = givenUuuid ?: uuid, ) } diff --git a/posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt b/posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt index 9d7e265d..69560916 100644 --- a/posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt +++ b/posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt @@ -14,6 +14,7 @@ import org.junit.Rule import org.junit.rules.TemporaryFolder import java.io.File import java.text.ParsePosition +import java.util.UUID import java.util.concurrent.Executors import kotlin.test.Test import kotlin.test.assertEquals @@ -313,7 +314,7 @@ internal class PostHogQueueTest { http.enqueue(MockResponse().setResponseCode(300).setBody("error")) - sut.add(generateEvent()) + sut.add(generateEvent(givenUuuid = UUID.randomUUID())) executor.awaitExecution()