Skip to content

Commit

Permalink
[Java] rework crash reporting tests (#100)
Browse files Browse the repository at this point in the history
* feat: control from rq

* fix: remoove sout line

* feat: increase timer

* fix: git action try

* fix: git actiooons

* fix: git action

* fix: undo git actions

* fix: wait for oobject not sleep

* chore: remove comment
  • Loading branch information
arifBurakDemiray authored Oct 6, 2023
1 parent e64e43d commit 6261758
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.Session;
Expand All @@ -16,13 +14,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.verification.VerificationMode;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -442,49 +436,43 @@ private void addLocation_base(Config config, Object expected) {

Assert.assertEquals(expected, session.params.get("location"));
}

/**
* "addCrashReport" with no consent to crash reporting
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should not be called
*/
@Test
public void addCrashReport_crashReportingNotEnabled() {
addCrashReport_base(TestUtils.getConfigSessions(), 0);
}

/**
* "addCrashReport"
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should be called once
*/
@Test
public void addCrashReport() {
addCrashReport_base(TestUtils.getConfigSessions(Config.Feature.CrashReporting), 1);
}

//todo long spy issue
///**
// * "addCrashReport" with no consent to crash reporting
// * mocked exception given to function and validating function calls
// * SDKCore.instance().onCrash() should not be called
// */
//@Test
//public void addCrashReport_crashReportingNotEnabled() {
// addCrashReport_base(TestUtils.getConfigSessions(), never());
//}
//
///**
// * "addCrashReport"
// * mocked exception given to function and validating function calls
// * SDKCore.instance().onCrash() should be called once
// */
//@Test
//public void addCrashReport() {
// addCrashReport_base(TestUtils.getConfigSessions(Config.Feature.CrashReporting), times(1));
//}
//
///**
// * "addCrashReport" with backend mode enabled
// * mocked exception given to function and validating function calls
// * SDKCore.instance().onCrash() should not be called and expected log should be logged
// */
//@Test
//public void addCrashReport_backendModeEnabled() {
// SessionImpl session = addCrashReport_base(TestUtils.getConfigSessions().enableBackendMode(), never());
// verify(session.L, times(1)).w("[SessionImpl] addCrashReport: Skipping crash, backend mode is enabled!");
//}
//
//private SessionImpl addCrashReport_base(Config config, VerificationMode verificationMode) {
// Countly.instance().init(config);
// SessionImpl session = (SessionImpl) Countly.session();
// //SDKCore.instance = spy(SDKCore.instance);
// //session.L = spy(session.L);
// session.addCrashReport(new Exception(), false);
//
// verify(SDKCore.instance, verificationMode).onCrash(any(), any(), anyBoolean(), any(), any(), any());
// return session;
//}
/**
* "addCrashReport" with backend mode enabled
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should not be called and expected log should be logged
*/
@Test
public void addCrashReport_backendModeEnabled() {
addCrashReport_base(TestUtils.getConfigSessions().enableBackendMode(), 0);
}

private void addCrashReport_base(Config config, int rqSize) {
Countly.instance().init(config);
SessionImpl session = (SessionImpl) Countly.session();
session.addCrashReport(new Exception(), false);
Assert.assertEquals(rqSize, TestUtils.getCurrentRQ().length);
}

/**
* "hashCode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void recordEventRegularFlow_base(boolean regularRecord) throws Interrupte

TestUtils.validateEQSize(0);

Thread.sleep(1000);
synchronized (tEvent) {
tEvent.wait(1000);
}

double targetDuration;
if (regularRecord) {
Expand Down

0 comments on commit 6261758

Please sign in to comment.