Skip to content
Merged
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 @@ -17,8 +17,9 @@
public class ModuleViewsTests {

@Before
public void beforeTest() {
public void beforeTest() throws InterruptedException {
TestUtils.createCleanTestState();
TestUtils.awaitStartOfSecond();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,14 @@ public void view() {
* start, stop and next view should be recorded to EQ
*/
@Test
public void view_stopStartedAndNext() {
public void view_stopStartedAndNext() throws InterruptedException {
InternalConfig config = new InternalConfig(TestUtils.getConfigSessions(Config.Feature.Views, Config.Feature.Events).setEventQueueSizeToSend(4));
config.viewIdGenerator = TestUtils.idGenerator();
Countly.instance().init(config);

SessionImpl session = (SessionImpl) Countly.session();
TestUtils.validateEQSize(0);
TestUtils.awaitStartOfSecond();
session.view("start");
TestUtils.validateEQSize(1);
session.view("next");
Expand Down
14 changes: 14 additions & 0 deletions sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,20 @@ public static Map<String, String> parseQueryParams(String data) {
*/
private static final double SLEEP_OVERRUN_TOLERANCE_SECONDS = 2.0;

/**
* Waits for the next second when the clock is past the first 200 ms of the current one. A view
* duration is the difference of two whole-second timestamps, so a view stopped right after it
* started reports 1 s when the two calls fall on either side of a second boundary.
*
* @throws InterruptedException when the wait is interrupted
*/
static void awaitStartOfSecond() throws InterruptedException {
long intoSecond = System.currentTimeMillis() % 1000;
if (intoSecond > 200) {
Thread.sleep(1000 - intoSecond);
}
}

static void validateEvent(EventImpl gonnaValidate, String key, Map<String, Object> segmentation, int count, Double sum, Double duration, String id, String pvid, String cvid, String peid) {
Assert.assertEquals(key, gonnaValidate.key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
@RunWith(JUnit4.class)
public class sc_MV_ManualViewTests {
@Before
public void beforeTest() {
public void beforeTest() throws InterruptedException {
TestUtils.createCleanTestState();
TestUtils.awaitStartOfSecond();
}

@After
Expand Down
Loading