Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 354afc79 authored by Matthew Sedam's avatar Matthew Sedam
Browse files

ContextHubTestModeManager: Reduce event probabilities

This CL reduces the probability that a duplication
or drop event occurs during the reliable message
test. This CL should fix failures where the events
were occurring too frequently, so even though the
code was working correctly and retrying messages,
all messages were being dropped leading to test
failure.

Bug: 333567700
Change-Id: I1fe7ed7bb0fbdfb755d59895c514c59111af1c42
Flag: TEST_ONLY
Test: Presubmits
parent 26e97845
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -29,19 +29,22 @@ import java.util.Random;
public class ContextHubTestModeManager {
    private static final String TAG = "ContextHubTestModeManager";

    /** Probability (in percent) of duplicating a message. */
    private static final int MESSAGE_DROP_PROBABILITY_PERCENT = 20;
    /** Probability of duplicating a message. */
    private static final double MESSAGE_DROP_PROBABILITY = 0.05;

    /** Probability (in percent) of duplicating a message. */
    private static final int MESSAGE_DUPLICATION_PROBABILITY_PERCENT = 20;
    /** Probability of duplicating a message. */
    private static final double MESSAGE_DUPLICATION_PROBABILITY = 0.05;

    /** The number of total messages to send when the duplicate event happens. */
    /** The number of total messages to send when the duplication event happens. */
    private static final int NUM_MESSAGES_TO_DUPLICATE = 3;

    /** A probability percent for a certain event. */
    private static final int MAX_PROBABILITY_PERCENT = 100;
    /**
     * The seed for the random number generator. This is used to make the
     * test more deterministic.
     */
    private static final long SEED = 0xDEADBEEF;

    private final Random mRandom = new Random();
    private final Random mRandom = new Random(SEED);

    /**
     * @return whether the message was handled
@@ -50,8 +53,7 @@ public class ContextHubTestModeManager {
    public boolean handleNanoappMessage(Runnable handleMessage, NanoAppMessage message) {
        if (Flags.reliableMessageDuplicateDetectionService()
                && message.isReliable()
                && mRandom.nextInt(MAX_PROBABILITY_PERCENT)
                        < MESSAGE_DUPLICATION_PROBABILITY_PERCENT) {
                && mRandom.nextDouble() < MESSAGE_DUPLICATION_PROBABILITY) {
            Log.i(TAG, "[TEST MODE] Duplicating message ("
                    + NUM_MESSAGES_TO_DUPLICATE
                    + " sends) with message sequence number: "
@@ -71,8 +73,7 @@ public class ContextHubTestModeManager {
    public boolean sendMessageToContextHub(NanoAppMessage message) {
        if (Flags.reliableMessageRetrySupportService()
                && message.isReliable()
                && mRandom.nextInt(MAX_PROBABILITY_PERCENT)
                        < MESSAGE_DROP_PROBABILITY_PERCENT) {
                && mRandom.nextDouble() < MESSAGE_DROP_PROBABILITY) {
            Log.i(TAG, "[TEST MODE] Dropping message with message sequence number: "
                    + message.getMessageSequenceNumber());
            return true;