Fix flaky limits test. 3/head
authorNick Vatamaniuc <vatamane@gmail.com>
Wed, 7 Oct 2015 17:09:33 +0000 (13:09 -0400)
committerNick Vatamaniuc <vatamane@gmail.com>
Wed, 7 Oct 2015 17:09:33 +0000 (13:09 -0400)
 In the limits test we check statistics with ets:info right after
 eviction. Sometimes ets:info does not update immediately.

 On first failure, delay for 1ms, then try again.

test/ets_lru_test.erl

index 8cfefcc49c18544a96a554ffe8f64516b1d996cb..50ba1b667ff005059a18f9322de79a4035499c65 100644 (file)
@@ -286,7 +286,15 @@ insert_kvs(_, _, 0, _) ->
 insert_kvs(Info, LRU, Count, Limit) ->
     ets_lru:insert(LRU, Count, 1.5234),
     case ets:info(lru_objects, Info) > Limit of
-        true -> erlang:error(exceeded_limit);
+        true ->
+            % Retry again as eviction statistics
+            % returned by ets:info() can be delayed.
+            timer:sleep(1),
+            case ets:info(lru_objects, Info) > Limit of
+                true ->
+                    erlang:error(exceeded_limit);
+                false -> true
+            end;
         false -> true
     end,
     insert_kvs(Info, LRU, Count - 1, Limit).