@@ -120,6 +120,95 @@ public void eventSaveScenario_changeDeviceIDWithoutMerge() throws JSONException
120120 ModuleUserProfileTests .validateUserProfileRequest (2 , 3 , TestUtils .map (), TestUtils .map ("theme" , "light_mode" ));
121121 }
122122
123+ /**
124+ * Related user properties should not be saved with session calls,
125+ * call order, user property before session, begin session, user property after begin session, update session, user property after update session, end session
126+ * generated request order begin_session + update_session + user properties + end_session
127+ * manual sessions are enabled
128+ * UPDATE: session calls now trigger saving properties like events as well
129+ * UPDATED_REQUEST_ORDER: user property before session + begin_session + user property after begin session + update_session + user property after update session + end_session
130+ */
131+ @ Test
132+ public void eventSaveScenario_sessionCallsTriggersSave_M () throws JSONException , InterruptedException {
133+ Countly countly = new Countly ().init (TestUtils .createBaseConfig ().enableManualSessionControl ().setTrackOrientationChanges (false ));
134+
135+ TestUtils .assertRQSize (0 );
136+ countly .userProfile ().setProperty ("before_session" , true );
137+
138+ countly .sessions ().beginSession ();
139+ TestUtils .assertRQSize (2 ); // only begin session request, UPDATE: user property request before session
140+ ModuleUserProfileTests .validateUserProfileRequest (0 , 2 , TestUtils .map (), TestUtils .map ("before_session" , true ));
141+ ModuleSessionsTests .validateSessionBeginRequest (1 , TestUtils .commonDeviceId );
142+
143+ countly .userProfile ().setProperty ("after_begin_session" , true );
144+ TestUtils .assertRQSize (2 ); // still begin session, UPDATE: user property request after begin session
145+ // no new user property request because it is validated along with begin session
146+
147+ Thread .sleep (2000 );
148+
149+ countly .sessions ().updateSession ();
150+ TestUtils .assertRQSize (4 ); // only begin session and update session requests, UPDATE: user property request after begin and update session
151+
152+ ModuleUserProfileTests .validateUserProfileRequest (2 , 4 , TestUtils .map (), TestUtils .map ("after_begin_session" , true ));
153+ ModuleSessionsTests .validateSessionUpdateRequest (3 , 2 , TestUtils .commonDeviceId );
154+
155+ countly .userProfile ().setProperty ("after_update_session" , true );
156+ TestUtils .assertRQSize (4 ); // still begin session and update session requests
157+ // no new user property request because it is validated along with update session
158+ Thread .sleep (2000 );
159+
160+ countly .sessions ().endSession ();
161+ TestUtils .assertRQSize (6 ); // begin, update, user properties and end session requests
162+ ModuleUserProfileTests .validateUserProfileRequest (4 , 6 , TestUtils .map (), TestUtils .map ("after_update_session" , true ));
163+ ModuleSessionsTests .validateSessionEndRequest (5 , 2 , TestUtils .commonDeviceId );
164+ }
165+
166+ /**
167+ * Related user properties should be saved with automatic session calls,
168+ * call order, user property before session, user property after begin session, session, user property after update session
169+ * generated request order user_properties + begin_session + user_properties + update_session + user properties + end_session
170+ */
171+ @ Test
172+ public void eventSaveScenario_sessionCallsTriggersSave_A () throws JSONException , InterruptedException {
173+ CountlyConfig config = TestUtils .createBaseConfig (TestUtils .getContext ()).setTrackOrientationChanges (false );
174+ TestLifecycleObserver testLifecycleObserver = new TestLifecycleObserver ();
175+ config .lifecycleObserver = testLifecycleObserver ;
176+ config .setUpdateSessionTimerDelay (3 );
177+ Countly countly = new Countly ().init (config );
178+
179+ TestUtils .assertRQSize (0 );
180+ countly .userProfile ().setProperty ("before_session" , true );
181+
182+ testLifecycleObserver .bringToForeground ();
183+ countly .onStart (null );
184+
185+ TestUtils .assertRQSize (2 );
186+ ModuleUserProfileTests .validateUserProfileRequest (0 , 2 , TestUtils .map (), TestUtils .map ("before_session" , true ));
187+ ModuleSessionsTests .validateSessionBeginRequest (1 , TestUtils .commonDeviceId );
188+
189+ countly .userProfile ().setProperty ("after_begin_session" , true );
190+ TestUtils .assertRQSize (2 );
191+
192+ Thread .sleep (3000 );
193+
194+ TestUtils .assertRQSize (4 );
195+
196+ ModuleUserProfileTests .validateUserProfileRequest (2 , 4 , TestUtils .map (), TestUtils .map ("after_begin_session" , true ));
197+ ModuleSessionsTests .validateSessionUpdateRequest (3 , 3 , TestUtils .commonDeviceId );
198+
199+ countly .userProfile ().setProperty ("after_update_session" , true );
200+ TestUtils .assertRQSize (4 );
201+
202+ Thread .sleep (2000 );
203+
204+ testLifecycleObserver .goToBackground ();
205+ countly .onStop ();
206+
207+ TestUtils .assertRQSize (6 );
208+ ModuleUserProfileTests .validateUserProfileRequest (4 , 6 , TestUtils .map (), TestUtils .map ("after_update_session" , true ));
209+ ModuleSessionsTests .validateSessionEndRequest (5 , 2 , TestUtils .commonDeviceId );
210+ }
211+
123212 /**
124213 * 1. 200_CNR_A
125214 * Init SDK
0 commit comments