Repository navigation
fix: Send pending flag analytics when the client is closed #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |||||||||||||
| import static org.mockito.ArgumentMatchers.any; | ||||||||||||||
| import static org.mockito.ArgumentMatchers.eq; | ||||||||||||||
| import static org.mockito.Mockito.doThrow; | ||||||||||||||
| import static org.mockito.Mockito.inOrder; | ||||||||||||||
| import static org.mockito.Mockito.mock; | ||||||||||||||
| import static org.mockito.Mockito.never; | ||||||||||||||
| import static org.mockito.Mockito.times; | ||||||||||||||
| import static org.mockito.Mockito.verify; | ||||||||||||||
| import static org.mockito.Mockito.when; | ||||||||||||||
|
|
@@ -16,13 +18,16 @@ | |||||||||||||
| import com.flagsmith.config.FlagsmithConfig; | ||||||||||||||
| import com.flagsmith.config.Retry; | ||||||||||||||
| import java.io.IOException; | ||||||||||||||
| import java.util.concurrent.CountDownLatch; | ||||||||||||||
| import java.util.concurrent.TimeUnit; | ||||||||||||||
|
|
||||||||||||||
| import lombok.SneakyThrows; | ||||||||||||||
| import okhttp3.Response; | ||||||||||||||
| import okhttp3.mock.MockInterceptor; | ||||||||||||||
| import org.junit.jupiter.api.Assertions; | ||||||||||||||
| import org.junit.jupiter.api.BeforeEach; | ||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||
| import org.mockito.InOrder; | ||||||||||||||
|
|
||||||||||||||
| public class AnalyticsProcessorTest { | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -100,6 +105,48 @@ public void testClose_ShutsDownExecutor() { | |||||||||||||
| verify(requestProcessor, times(1)).close(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Test | ||||||||||||||
| public void testClose_FlushesPendingAnalyticsBeforeShutdown() { | ||||||||||||||
| analytics.trackFeature("foo"); | ||||||||||||||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||
| Assertions.assertFalse(analytics.getAnalyticsData().isEmpty()); | ||||||||||||||
|
|
||||||||||||||
| analytics.close(); | ||||||||||||||
|
|
||||||||||||||
| InOrder inOrder = inOrder(requestProcessor); | ||||||||||||||
| inOrder.verify(requestProcessor).executeAsync(any(), any()); | ||||||||||||||
| inOrder.verify(requestProcessor).close(); | ||||||||||||||
| Assertions.assertTrue(analytics.getAnalyticsData().isEmpty()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Test | ||||||||||||||
| @SneakyThrows | ||||||||||||||
| public void testClose_WaitsForActiveFlushBeforeShutdown() { | ||||||||||||||
| CountDownLatch flushStarted = new CountDownLatch(1); | ||||||||||||||
| CountDownLatch finishFlush = new CountDownLatch(1); | ||||||||||||||
| when(api.newPostRequest(any(), any())).thenAnswer(invocation -> { | ||||||||||||||
| flushStarted.countDown(); | ||||||||||||||
| finishFlush.await(5, TimeUnit.SECONDS); | ||||||||||||||
| return null; | ||||||||||||||
| }); | ||||||||||||||
| analytics.trackFeature("foo"); | ||||||||||||||
| Thread flusher = new Thread(analytics::flush); | ||||||||||||||
| flusher.start(); | ||||||||||||||
| Assertions.assertTrue(flushStarted.await(5, TimeUnit.SECONDS)); | ||||||||||||||
|
|
||||||||||||||
| Thread closer = new Thread(analytics::close); | ||||||||||||||
| closer.start(); | ||||||||||||||
| closer.join(500); | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The 500 ms join does not prove Prompt for AI agents
Suggested change
|
||||||||||||||
| verify(requestProcessor, never()).close(); | ||||||||||||||
|
|
||||||||||||||
| finishFlush.countDown(); | ||||||||||||||
| flusher.join(5000); | ||||||||||||||
| closer.join(5000); | ||||||||||||||
|
|
||||||||||||||
| InOrder inOrder = inOrder(requestProcessor); | ||||||||||||||
| inOrder.verify(requestProcessor).executeAsync(any(), any()); | ||||||||||||||
| inOrder.verify(requestProcessor).close(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Test | ||||||||||||||
| @SneakyThrows | ||||||||||||||
| public void AnalyticsProcessor_longAdderGetsSerializedCorrectly() { | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.