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

Commit a0060489 authored by Yu Shan's avatar Yu Shan
Browse files

Increase timer test tolerance.

This test was flaky on cf. Increase the tolerance to make it stable.
This CL also modifies subscribe test to not rely on sleep to make
it stable.

Test: Presubmit
Bug: 268603744 270074790
Change-Id: I4a8003be152ef0a1f409f3705892fffee58170dd
parent dd9febd1
Loading
Loading
Loading
Loading
+20 −10
Original line number Original line Diff line number Diff line
@@ -124,6 +124,17 @@ class DefaultVhalImplTest : public ::testing::Test {
    android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue;
    android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue;
    android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue;
    android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue;


    // Wait until receive enough events in receivedEvents.
    void waitForEvents(std::vector<VehiclePropValuePtr>* receivedEvents, size_t count) {
        while (receivedEvents->size() < count) {
            mEventQueue.waitForItems();
            auto newEvents = mEventQueue.flush();
            for (size_t i = 0; i < newEvents.size(); i++) {
                receivedEvents->push_back(std::move(newEvents[i]));
            }
        }
    }

  private:
  private:
    void onHalEvent(VehiclePropValuePtr v) {
    void onHalEvent(VehiclePropValuePtr v) {
        if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) {
        if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) {
@@ -314,26 +325,25 @@ TEST_F(DefaultVhalImplTest, testSubscribe) {


    ASSERT_EQ(StatusCode::OK, status);
    ASSERT_EQ(StatusCode::OK, status);


    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    std::vector<VehiclePropValuePtr> receivedEvents;
    waitForEvents(&receivedEvents, 5);


    // Modify the speed after 0.5 seconds.
    // Modify the speed after 5 events arrive.
    VehiclePropValue value;
    VehiclePropValue value;
    value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
    value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED);
    value.value.floatValues.resize(1);
    value.value.floatValues.resize(1);
    value.value.floatValues[0] = 1.0f;
    value.value.floatValues[0] = 1.0f;
    ASSERT_EQ(StatusCode::OK, mHal->set(value));
    ASSERT_EQ(StatusCode::OK, mHal->set(value));


    std::this_thread::sleep_for(std::chrono::milliseconds(500));
    waitForEvents(&receivedEvents, 10);

    auto events = mEventQueue.flush();
    ASSERT_LE((size_t)10, events.size());


    // The first event should be the default value.
    // The first event should be the default value.
    ASSERT_EQ((size_t)1, events[0]->value.floatValues.size());
    ASSERT_EQ((size_t)1, receivedEvents[0]->value.floatValues.size());
    EXPECT_EQ(0.0f, events[0]->value.floatValues[0]);
    EXPECT_EQ(0.0f, receivedEvents[0]->value.floatValues[0]);
    // The last event should be the value after update.
    // The last event should be the value after update.
    ASSERT_EQ((size_t)1, events[events.size() - 1]->value.floatValues.size());
    const auto& lastEvent = receivedEvents[receivedEvents.size() - 1];
    EXPECT_EQ(1.0f, events[events.size() - 1]->value.floatValues[0]);
    ASSERT_EQ((size_t)1, lastEvent->value.floatValues.size());
    EXPECT_EQ(1.0f, lastEvent->value.floatValues[0]);
}
}


TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) {
TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@ TEST(RecurrentTimerTest, multipleIntervals) {
    std::this_thread::sleep_for(milliseconds(100));
    std::this_thread::sleep_for(milliseconds(100));
    // This test is unstable, so set the tolerance to 50.
    // This test is unstable, so set the tolerance to 50.
    ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50);
    ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50);
    ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 5);
    ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 10);
}
}


}  // anonymous namespace
}  // anonymous namespace