Skip to content

Commit

Permalink
fix: do not clear events and reload flags after reset is called (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Aug 30, 2024
1 parent bb0f3d3 commit 9012e5d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Next

- fix: do not clear events when reset is called ([#170](https://github.com/PostHog/posthog-android/pull/170))
- fix: reload feature flags as anon user after reset is called ([#170](https://github.com/PostHog/posthog-android/pull/170))

## 3.6.0 - 2024-08-29

- recording: expose session id ([#166](https://github.com/PostHog/posthog-android/pull/166))
Expand Down
9 changes: 6 additions & 3 deletions posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,19 @@ public class PostHog private constructor(
val except = listOf(VERSION, BUILD)
getPreferences().clear(except = except)
featureFlags?.clear()
queue?.clear()
replayQueue?.clear()
featureFlagsCalled.clear()

synchronized(identifiedLock) {
isIdentifiedLoaded = false
}

endSession()
startSession()

// reload flags as anon user
// only because of testing in isolation, this flag is always enabled
if (reloadFeatureFlags) {
reloadFeatureFlags()
}
}

private fun isEnabled(): Boolean {
Expand Down
20 changes: 19 additions & 1 deletion posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ internal class PostHogTest {
val http = mockHttp()
val url = http.url("/")

val sut = getSut(url.toString(), preloadFeatureFlags = false)
val sut = getSut(url.toString(), preloadFeatureFlags = false, reloadFeatureFlags = false)

sut.capture(
EVENT,
Expand Down Expand Up @@ -1100,6 +1100,24 @@ internal class PostHogTest {
sut.close()
}

@Test
fun `reset reloads flags as anon user`() {
val http = mockHttp()
val url = http.url("/")

val sut = getSut(url.toString(), preloadFeatureFlags = false)

sut.reset()

featureFlagsExecutor.shutdownAndAwaitTermination()

val request = http.takeRequest()
assertEquals(1, http.requestCount)
assertEquals("/decide/?v=3", request.path)

sut.close()
}

@Test
fun `logger uses System out by default`() {
val http = mockHttp()
Expand Down

0 comments on commit 9012e5d

Please sign in to comment.