Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ String getSessionId() {
}
// value will never be null
currentValue = requireNonNull(value.get());
timeoutHandler.bump();
}

timeoutHandler.bump();
// sessionId change listener needs to be called after bumping the timer because it may
// create a new span
SessionIdChangeListener sessionIdChangeListener = this.sessionIdChangeListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.android;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -69,7 +70,7 @@ void shouldCallSessionIdChangeListener() {
String firstSessionId = sessionId.getSessionId();
clock.advance(3, TimeUnit.HOURS);
sessionId.getSessionId();
verify(timeoutHandler, times(2)).bump();
verify(timeoutHandler, times(0)).bump();
verify(listener, never()).onChange(anyString(), anyString());

clock.advance(1, TimeUnit.HOURS);
Expand All @@ -85,14 +86,32 @@ void shouldCreateNewSessionIdAfterTimeout() {
SessionId sessionId = new SessionId(timeoutHandler);

String value = sessionId.getSessionId();
verify(timeoutHandler).bump();

assertEquals(value, sessionId.getSessionId());
verify(timeoutHandler, times(2)).bump();
verify(timeoutHandler, times(0)).bump();

when(timeoutHandler.hasTimedOut()).thenReturn(true);

assertNotEquals(value, sessionId.getSessionId());
verify(timeoutHandler, times(3)).bump();
verify(timeoutHandler, times(1)).bump();
}

@Test
void shouldNotUpdateSessionIdInForeground() {
timeoutHandler.onApplicationForegrounded();
SessionId sessionId = new SessionId(timeoutHandler);
String value = sessionId.getSessionId();
assertEquals(value, sessionId.getSessionId());
assertFalse(timeoutHandler.hasTimedOut());
}

@Test
void shouldUpdateSessionIdIfTimeoutAndInBackground() {
timeoutHandler.onApplicationBackgrounded();
SessionId sessionId = new SessionId(timeoutHandler);
when(timeoutHandler.hasTimedOut()).thenReturn(true);
String value = sessionId.getSessionId();
assertTrue(timeoutHandler.hasTimedOut());
assertNotEquals(value, sessionId.getSessionId());
}
}