Skip to content

Commit

Permalink
[routing-manager] enhance TestPrefixStaleTime() (openthread#10342)
Browse files Browse the repository at this point in the history
This commit changes unit test `TestPrefixStaleTime()` so that a route
prefix is advertised with a lifetime of 800 seconds, which is longer
than the `kStaleTime` of 600 seconds. With this change, the entry
will not expire and become stale at the same time. This simultaneous
expiration could cause issues depending on the order of execution of
`mStaleTimer` and `mExpirationTimer`, which would be scheduled for
the same time. With this change, the entry will still be valid (due
to the lifetime of 800 seconds) when the stale timer fires after 600
seconds. This ensures that the test runs consistently and does not
depend on the order in which timer callbacks fire.
  • Loading branch information
abtink authored Jun 5, 2024
1 parent 18f7bc3 commit d6eb56c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/unit/test_routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2692,11 +2692,11 @@ void TestPrefixStaleTime(void)

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Advertise a route prefix with 200 seconds lifetime from router A.
// Advertise the same route prefix with 500 seconds lifetime from
// Advertise the same route prefix with 800 seconds lifetime from
// router B.

SendRouterAdvert(routerAddressA, {Rio(routePrefix, 200, NetworkData::kRoutePreferenceMedium)});
SendRouterAdvert(routerAddressB, {Rio(routePrefix, 500, NetworkData::kRoutePreferenceMedium)});
SendRouterAdvert(routerAddressB, {Rio(routePrefix, 800, NetworkData::kRoutePreferenceMedium)});

AdvanceTime(10);

Expand All @@ -2705,7 +2705,7 @@ void TestPrefixStaleTime(void)
// is present in the table.

VerifyPrefixTable({RoutePrefix(routePrefix, 200, NetworkData::kRoutePreferenceMedium, routerAddressA),
RoutePrefix(routePrefix, 500, NetworkData::kRoutePreferenceMedium, routerAddressB)});
RoutePrefix(routePrefix, 800, NetworkData::kRoutePreferenceMedium, routerAddressB)});

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Wait for a period exceeding the 200-second lifetime of the route
Expand All @@ -2716,19 +2716,21 @@ void TestPrefixStaleTime(void)

sRsEmitted = false;

AdvanceTime(490 * 1000);
AdvanceTime(590 * 1000);

VerifyOrQuit(!sRsEmitted);

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Check the discovered prefix table and ensure router A entry is
// expired and removed.

VerifyPrefixTable({RoutePrefix(routePrefix, 500, NetworkData::kRoutePreferenceMedium, routerAddressB)});
VerifyPrefixTable({RoutePrefix(routePrefix, 800, NetworkData::kRoutePreferenceMedium, routerAddressB)});

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Wait longer than 500-second lifetime of prefix advertised by
// router B. Now we should see RS messages emitted.
// Wait for the 600-second stale time to expire. This is shorter
// than the 800-second lifetime of the prefix advertised by
// Router B, so the 600-second value will be used. We should now
// observe RS messages being transmitted.

AdvanceTime(20 * 1000);

Expand Down

0 comments on commit d6eb56c

Please sign in to comment.